AcWing 1478. 签到与签出
原题链接
简单
作者:
Wegoon
,
2021-09-04 14:38:49
,
所有人可见
,
阅读 288
知识点:模拟、字符串处理
我的做法
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 15;
int n, id1, id2;
string name[N], s[N], e[N];
int main() {
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> name[i] >> s[i] >> e[i];
string s1 = s[0], s2 = e[0];
for (int i = 0; i < n; i ++ ) {
if(s[i] < s1) s1 = s[i], id1 = i;
if(e[i] > s2) s2 = e[i], id2 = i;
}
cout << name[id1] << ' ' << name[id2] << endl;
return 0;
}
看了y总的代码后进行的改进
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 15;
int n, id1, id2;
string name, s, e, s1, s2, n1, n2;
int main() {
cin >> n;
for (int i = 0; i < n; i ++ ) {
cin >> name >> s >> e;
if(!i || s < s1) s1 = s, n1 = name;
if(!i || e > s2) s2 = e, n2 = name;
}
cout << n1 << ' ' << n2 << endl;
return 0;
}