AcWing 417. 不高兴的津津
原题链接
简单
作者:
Value
,
2020-09-07 17:27:32
,
所有人可见
,
阅读 398
当排序去做
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
int id;
int sum;
}day[10];
bool cmp(node p, node q){
if(p.sum != q.sum) return p.sum > q.sum;
else return p.id < q.id;
}
int main(){
for(int i = 0; i < 7; i ++ ){
int x, y; cin >> x >> y;
day[i].sum = x + y;
day[i].id = i;
}
sort(day, day + 7, cmp);
cout << day[0].id + 1 << endl;
return 0;
}
后来发现可以…,看来以前是想复杂了!
#include <iostream>
using namespace std;
int main(){
int res = 0, maxv = 0;
for(int i = 1; i <= 7; i ++ ){
int a, b; cin >> a >> b;
if(a + b > maxv){
maxv = a + b;
res = i;
}
}
if(maxv <= 8) res = 0;
cout << res << endl;
return 0;
}