Mr_HO1A

Date and Time [Mockvita 2]

Jun 15th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.39 KB | None | 0 0
  1.     // Author - Aman Vishwakarma
  2.     // Laptop 2 [Arch VM 2]
  3.  
  4.     #include<iostream>
  5.     #include<vector>
  6.     #include<utility>
  7.     #include<queue>
  8.     #include<stack>
  9.     #include<math.h>
  10.     #include<algorithm>
  11.     #include<string>
  12.     using namespace std;
  13.     #define whatis(x) cout<<#x<<" : "<<x<<endl
  14.     int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  15.     int hashfn[10] = {} ;
  16.     int months(int i) {
  17.         int temp = i;
  18.             int l  = temp % 10;
  19.             temp = temp / 10;
  20.             if( ( l != temp ) && hashfn[l]>0 && hashfn[temp] > 0)  {
  21.                 hashfn[l]--;
  22.                 hashfn[temp]--;
  23.                 return i;
  24.             }
  25.             else if( l == temp && hashfn[l]>1 ) {
  26.                     hashfn[l]--;
  27.                     hashfn[l]--;
  28.                     return i;
  29.             }
  30.     return -1;
  31.     }
  32.     vector<int> switch2pre (vector<int> &upd) {
  33.         vector<int> upd2(10, 0);
  34.         for(int i = 0; i<10; i++) {
  35.             hashfn[i] = upd[i];
  36.             upd2[i] = upd[i];
  37.         }
  38.         return upd2;
  39.     }
  40.     vector<int> updated () {
  41.         vector<int> upd2(10, 0);
  42.         for(int i = 0; i<10; i++) {
  43.            
  44.             upd2[i] = hashfn[i];
  45.         }
  46.         return upd2;
  47.     }
  48.     int main() {
  49.         vector<int> upd(10, 0);
  50.         for(int i = 0; i<12; i++) {
  51.             int d;
  52.             char ch;
  53.             cin>>d;
  54.             if(i != 11)
  55.             cin>>ch;
  56.             hashfn[d]++;
  57.             upd[d]++;
  58.         }
  59.         //initialised
  60.         int mm = -1, dd = -1, hh = -1, ss = -1;
  61.         for(int i = 12; i>0; i--) {
  62.             //For MONTHS
  63.             vector<int> upd2 = switch2pre(upd);
  64.            
  65.             mm = months(i);
  66.             if(mm != -1) {
  67.                 upd2 = updated();
  68.                
  69.                 for(int j = days[i-1]; j>0; j--) {
  70.                 //For DAYS
  71.                     vector<int> upd3 = switch2pre(upd2);
  72.                
  73.                     dd = months(j);
  74.                    
  75.                     if(dd!=-1) {
  76.                         upd3 = updated();    
  77.                    
  78.                         for(int k =23; k>=0; k--) {
  79.                             //For HOURS
  80.                             vector<int> upd4 = switch2pre(upd3);
  81.                            
  82.                             hh = months(k);
  83.                            
  84.                             if(hh != -1) {
  85.                                 upd4 = updated();
  86.                                
  87.                                 for(int z = 59; z>=0; z-- ){
  88.                                     //FOR SECONDS
  89.                                     vector<int> upd5 = switch2pre(upd4);
  90.                                
  91.                                     ss = months(z);
  92.                                    
  93.                                     if(ss != -1) break;
  94.                                 }
  95.                             if(ss!=-1)
  96.                             break;
  97.                             }
  98.                             }
  99.                     if(ss!=-1)
  100.                     break;
  101.                     }
  102.                 }
  103.             if(ss!=-1)
  104.             break;
  105.             }
  106.         }
  107.         if( mm == -1 || ss == -1 || dd == -1 | hh == -1) cout<<0;
  108.         else printf("%02d/%02d %02d:%02d", mm, dd, hh, ss);
  109.    
  110.        
  111.         return 0;
  112.     }
Add Comment
Please, Sign In to add comment