mhdew

LA 7014

Sep 9th, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ///Template
  6. #define in1()    freopen("C:\\Users\\SHESHER\\Rest\\Desktop\\MY COMPUTER\\Code\\Template\\CB\\input.txt", "r", stdin);
  7. #define out1()   freopen("C:\\Users\\SHESHER\\Rest\\Desktop\\MY COMPUTER\\Code\\Template\\CB\\output 2.txt", "w", stdout);
  8.  
  9.  
  10. //Data types
  11. #define l       long
  12. #define ll      long long
  13. #define llu     unsigned long long
  14.  
  15. //loop
  16. #define f1(i,x,y)   for(int i=x;i<=y;i++)
  17.  
  18. //Constants
  19. #define MAX     10000007
  20. #define PI      acos(-1.0)
  21.  
  22. int flag[1111];
  23. map<char, int> mp;
  24. map<char, int> :: iterator it;
  25.  
  26. struct info
  27. {
  28.     int t1, hh, mm, ss;
  29.     char pn;
  30.     char vr[100];
  31. };
  32.  
  33. bool cmp(struct info a, struct info b)
  34. {
  35.     if(a.hh==b.hh){
  36.         if(a.mm==b.mm){
  37.             return a.ss<b.ss;
  38.         }
  39.         else return a.mm<b.mm;
  40.     }
  41.     else return a.hh<b.hh;
  42. }
  43. bool con1(int t)
  44. {
  45.     for(int i=1;i<=t;i++){
  46.         if(flag[i]==0){
  47.             return 0;
  48.         }
  49.     }
  50.     return 1;
  51. }
  52.  
  53. bool con2(int t, int p)
  54. {
  55.     for(int i=1;i<=t;i++){
  56.         if(flag[i]==p){
  57.             return 0;
  58.         }
  59.     }
  60.     return 1;
  61. }
  62.  
  63. bool con3(int p)
  64. {
  65.     for(int i=0;i<p;i++){
  66.         char ch='A'+i;
  67.         if(mp[ch]==0){
  68.             return 0;
  69.         }
  70.     }
  71.     return 1;
  72. }
  73.  
  74. bool con4(int p, int t)
  75. {
  76.     for(int i=0;i<p;i++){
  77.         char ch='A'+i;
  78.         if(mp[ch]==t){
  79.             return 0;
  80.         }
  81.     }
  82.     return 1;
  83. }
  84.  
  85. int main()
  86. {
  87. //    in1();
  88. //    out1();
  89.     for(;;){
  90.         int t, p, s;
  91.         cin>>t>>p>>s;
  92.  
  93.         if(t==0 && p==0 && s==0) break;
  94.         memset(flag, 0, sizeof(flag));
  95.         mp.clear();
  96.  
  97.         struct info a[11111];
  98.         int st[10];
  99.         int ed[10];
  100.         bool f=0, f2=0;
  101.  
  102.         for(int i=0;i<s;i++){
  103.             scanf("%d %c %d:%d:%d ", &a[i].t1,&a[i].pn,&a[i].hh,&a[i].mm,&a[i].ss);
  104.             gets(a[i].vr);
  105.         }
  106.  
  107. //        for(int i=0;i<s;i++){
  108. //            printf("%d %c %d:%d:%d %s\n", a[i].t1,a[i].pn,a[i].hh,a[i].mm,a[i].ss,a[i].vr);
  109. //        }
  110. //        cout<<endl;
  111.         sort(a, a+s, cmp);
  112. //        for(int i=0;i<s;i++){
  113. //            printf("%d %c %d:%d:%d %s\n", a[i].t1,a[i].pn,a[i].hh,a[i].mm,a[i].ss,a[i].vr);
  114. //        }
  115.  
  116. //            cout<<t1<<" "<<pn<<" "<<hh<<mm<<ss<<" "<<vr<<endl;
  117.         for(int i=0;i<s;i++){
  118.             if(a[i].vr[0]=='Y'){
  119.                 flag[a[i].t1]++;
  120.                 mp[a[i].pn]++;
  121.             }
  122.  
  123. //            for(int i=1;i<=t;i++){
  124. //                cout<<flag[i];
  125. //            }
  126. //            cout<<endl;
  127. //
  128. //            cout<<con1(t)<<" "<<con2(t,p)<<" "<<con3(p)<<" "<<con4(p,t)<<endl;
  129.  
  130.             if(!f){
  131.                 if(con1(t) && con2(t,p) && con3(p) && con4(p,t)){
  132.                     st[0]=a[i].hh;
  133.                     st[1]=a[i].mm;
  134.                     st[2]=a[i].ss;
  135.                     f=1;
  136.                 }
  137.             }
  138.             else if(!f2){
  139.                 if(!con1(t) || !con2(t,p) || !con3(p) || !con4(p,t)){
  140.                     ed[0]=a[i].hh;
  141.                     ed[1]=a[i].mm;
  142.                     ed[2]=a[i].ss;
  143.                     f2=1;
  144.                 }
  145.             }
  146.         }
  147.         if(f){
  148.             printf("%02d:%02d:%02d ", st[0],st[1],st[2]);
  149.         }
  150.         else if(!f){
  151.             printf("--:--:-- ");
  152.         }
  153.         if(f2){
  154.             printf("%02d:%02d:%02d\n", ed[0],ed[1],ed[2]);
  155.         }
  156.         else if(!f2){
  157.             printf("--:--:--\n");
  158.         }
  159. //    cout<<endl;
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment