HDU 2022 海选女主角(水~)

来源:互联网 发布:淘宝黑搜是什么意思 编辑:程序博客网 时间:2024/04/29 16:05

Description
给出一个m*n的数值矩阵,输出其中绝对值最大的数的行列数及其值,如果有多个数绝对值一样则输出最前面一个
Input
输入数据有多组,每组的第一行是两个整数m和n,表示行列数,然后是m行整数,每行有n个,以文件尾结束输入
Output
对于每组输入数据,输出三个整数x,y和s,分别表示绝对值最大的数的行号、列号和分数(行号和列号从一开始,如果有多个绝对值一样,那么输出排在最前面的一个(即行号最小的那个,如果行号相同则取列号最小的那个))
Sample Input
2 3
1 4 -3
-7 3 0
Sample Output
2 1 -7
Solution
水题
Code

#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){    int m,n;    while(scanf("%d%d",&m,&n)!=EOF)    {        int d;        int ansm,ansn,ans=0;        for(int i=1;i<=m;i++)            for(int j=1;j<=n;j++)            {                scanf("%d",&d);                if(abs(d)>abs(ans))                    ans=d,ansm=i,ansn=j;            }        printf("%d %d %d\n",ansm,ansn,ans);    }     return 0;}
0 0
原创粉丝点击