标签:
这道题本来想用结构体排序,想想都烦死了
又来用一个标记数组,先标记最长的,再在最长的里面标记最细的,最后在标记的里面输出编号最大的
#include <iostream> #include <cstring> using namespace std; const int C = 1010; int a[C]; int b[C]; int c[C]; int sign[C]; int Max = 0; int Maxc = 0; int Min = 1000000000; int main() { int n; cin >> n; int m; while(n--) { Max = 0; Maxc = 0; Min = 1000000000; memset(sign,0,sizeof(sign)); cin >> m; for(int i = 0 ; i < m ;i ++) cin >> a[i] >> b[i] >> c[i]; for(int i = 0; i < m; i++) if(a[i] > Max) Max = a[i]; for(int i = 0; i < m; i++) if(a[i] == Max) sign[i] = 1; for(int i = 0; i < m; i++) if(sign[i]&&b[i] < Min) Min = b[i]; for(int i = 0; i < m ; i++) if(sign[i]&& b[i] != Min) sign[i] = 0; for(int i = 0; i < m; i++) if(sign[i]&& c[i] > Maxc) Maxc = c[i]; cout << Maxc << endl; } return 0; }
最优代码,人家根本连数组都没开,节省了大量的代码,简洁清晰
#include<stdio.h> int main() { int n,m,i,a,b,c,x,y,z; scanf("%d",&n); while(n--) { scanf("%d",&m); a=0;b=0;c=0; for(i=0;i<m;i++) { scanf("%d%d%d",&x,&y,&z); if(x>a||x==a&&y<b||x==a&&y==b&&z>c) { a=x;b=y;c=z; } } printf("%d\n",c); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ekinzhang/p/4375437.html