一噪服、注意:
-
標(biāo)準(zhǔn)格式的時(shí)間可以直接進(jìn)行大小比較
image.png
//定義結(jié)構(gòu)單元
struct Unit{
string ID;
string inTime;
string outTime;
};
//根據(jù)進(jìn)入時(shí)間進(jìn)行排序
bool cmp1(Unit a,Unit b)
{
string ain = a.inTime;
string bin = b.inTime;
return ain < bin; //小邓了,返回的是true,從小到大排列
}
sort(n,n+M,cmp1); //根據(jù)進(jìn)入時(shí)間進(jìn)行排序
cout <<n[0].ID<<" ";
- 如果實(shí)在解決不了問題恨诱,選擇切割,先比較時(shí)間骗炉,觀察是否能夠AC照宝,如果不可以,則進(jìn)一步切割比較
- int number = stoi(string); //字符串?dāng)?shù)字變?yōu)閕nt型整數(shù)
- string s = to_string(number); //數(shù)字(int float double)變?yōu)樽址?/li>
int min_h = 25; //最早時(shí)間
int max_h = 0; //最晚時(shí)間
for(int i=0;i<M;i++)
{
int time1 = stoi(n[i].inTime.substr(0,2)); //小時(shí)
int time11 = stoi(n[i].outTime.substr(0,2));
if(time11 > max_h)
max_h =time11;
if(time1 < min_h)
min_h = time1;
}
for(int i=0;i<M;i++)
{
int time2 = stoi(n[i].inTime.substr(0,2)); //小時(shí)
int time22 = stoi(n[i].outTime.substr(0,2));
if(time2 == min_h)
cout <<n[i].ID<<" ";
if(time22 == max_h)
cout <<n[i].ID;
}
- 單詞:
- a positive integer M: 一個(gè)正整數(shù)M
- a non-negative integer N: 一個(gè)非負(fù)整數(shù)N