1006. Sign In and Sign Out (25)

    xiaoxiao2023-11-21  4

    考查知识点:查找元素

    思路:简单的一题写了一个多小时,2333,简单来说就是每输入一组数据,跟两个临时变量比较时间的先后,重点在于如何比较,这里依次比较时分秒,最后临时变量所保存的即为最后的结果。看不懂留言哦!!

    #include<cstdio> #include<cstring> struct Person{ char ID[20]; char unlock[10]={'2','4',':','6','0',':','6','0'}; char lock[10]={'0','0',':','0','0',':','0','0'}; }; int main(){ int M; Person p,temp1,temp2; scanf("%d",&M); for(int i=0;i<M;i++){ int h,m,s,hh,mm,ss,h1,h2,m1,m2,s1,s2; scanf("%s%s%s",p.ID,p.unlock,p.lock); sscanf(p.lock,"%d:%d:%d",&h,&m,&s); sscanf(p.unlock,"%d:%d:%d",&hh,&mm,&ss); sscanf(temp1.lock,"%d:%d:%d",&h1,&m1,&s1); sscanf(temp2.unlock,"%d:%d:%d",&h2,&m2,&s2); if(h>h1) temp1=p; else if(h==h1&&m>m1) temp1=p; else if(m==m1&&s>s1) temp1=p; if(hh<h2) temp2=p; else if(hh==h2&&mm<m2) temp2=p; else if(mm==m2&&ss<s2) temp2=p; } printf("%s %s",temp2.ID,temp1.ID); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1284164.html
    最新回复(0)