fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int clc(string tm,string zone)
  7. {
  8. int sum = 0;
  9.  
  10. if(zone == "PM"){
  11. if(tm[0] != '1' && tm[1] != '2') sum = 12*3600;
  12. }
  13.  
  14. int s = 0,d=3600;
  15. for(int i=0;i<tm.size();i++){
  16. if(tm[i]==':'){
  17. sum += s * d;
  18. d /= 60;
  19. s = 0;
  20. }
  21. else s = (s*10) + tm[i]-'0';
  22. }
  23. sum += s;
  24. return sum;
  25. }
  26. int main()
  27. {
  28.  
  29. string str[200];
  30. int ttl = 0,days=0;
  31.  
  32. while(cin>>str[0]){
  33. days++;
  34. for(int i=1;i<=12;i++) cin>>str[i];
  35. ttl += clc(str[10],str[11]) - clc(str[7],str[8]);
  36. }
  37.  
  38. int avg = ttl / days;
  39.  
  40. cout<<"Total Attendance : "<<days<<" Days"<<endl<<endl;
  41.  
  42.  
  43. int hour = ttl / 3600; ttl %= 3600;
  44. int minute = ttl / 60; ttl %= 60;
  45. cout<<"Total Office Time : "<<endl;
  46. cout<<" "<<hour<<" Hours "<<minute<<" Minutes "<<ttl<<" Seconds"<<endl<<endl;
  47.  
  48. int h = avg / 3600; avg %= 3600;
  49. int m = avg / 60; avg %= 60;
  50. int s = avg;
  51. cout<<"Average Time Per Day : "<<endl;
  52. cout<<" "<<h<<" Hours "<<m<<" Minutes "<<s<<" Seconds"<<endl<<endl;
  53.  
  54.  
  55. }
  56.  
Success #stdin #stdout 0.01s 5276KB
stdin
16 Oct 2024	8:10:00 AM	4:00:00 PM	7:49:35 AM	N	4:14:01 PM	N
19 Oct 2024	8:10:00 AM	4:00:00 PM	7:47:15 AM	N	4:21:20 PM	N
20 Oct 2024	8:10:00 AM	4:00:00 PM	7:42:59 AM	N	6:27:17 PM	N
21 Oct 2024	8:10:00 AM	4:00:00 PM	12:19:41 PM	Y	5:45:43 PM	N
22 Oct 2024	8:10:00 AM	4:00:00 PM	7:58:56 AM	N	4:12:49 PM	N
23 Oct 2024	8:10:00 AM	4:00:00 PM	8:03:51 AM	N	4:02:45 PM	N
stdout
Total Attendance : 6 Days

Total Office Time : 
                    49 Hours 21 Minutes 38 Seconds

Average Time Per Day : 
                       8 Hours 13 Minutes 36 Seconds