2023-1
作者:
许鑫蓁
,
2025-03-09 11:07:38
· 江西
,
所有人可见
,
阅读 4
2023-1
1)被devc的log关键字卡了一下,所以命名要注意避开,你就用一些拼音或者abc命名得了。
2)另外就是判断是否符合条件的时候想的太复杂,我一开始从正面想的,正面不好想,从反面想逻辑就会简单很多。要注意
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct log1{
string phone;
char pos;
string in;
string out;
};
int main()
{
vector<log1> logs, res, target;
int n;
cin >> n;
while(n --)
{
string x, y, z;
char c;
cin >> x >> c >> y >> z;
logs.push_back({x, c, y, z});
}
string fi;
cin >> fi;
// cout << fi << endl;
// cout << logs.size() << endl;
for(auto c : logs)
{
if(c.phone == fi) target.push_back(c);
}
// cout << target.size() << endl;
// cout << target[0].in << endl;
for(auto c : logs)
{
if(c.phone != fi && c.pos == target[0].pos)
{
if(!(c.in > target[0].out || c.out < target[0].in))
res.push_back(c);
}
}
// cout << res.size() << endl;
sort(res.begin(), res.end(), [&](log1 a, log1 b){
if(a.in != b.in) return a.in < b.in;
else return a.phone < b.phone;
});
for(auto c : res)
{
cout << c.phone << " " << c.pos << " " << c.in << " " << c.out << endl;
}
return 0;
}
样例:
7
11111 A 121000 225959
22222 B 080000 225959
33333 A 100000 110000
44444 B 101000 110000
55555 A 120000 131000
66666 A 225959 235959
77777 A 100000 120000
11111
输出:
55555 A 120000 131000
66666 A 225959 235959
样例:
7
11111 A 101000 225959
22222 B 080000 225959
33333 A 100000 110000
44444 B 101000 110000
55555 A 120000 131000
66666 A 225959 235959
77777 A 100000 120000
11111
输出:
33333 A 100000 110000
77777 A 100000 120000
55555 A 120000 131000
66666 A 225959 235959