Advertisement
inhuman_Arif

uva 154

Oct 25th, 2021
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int main()
  7. {
  8.     #ifndef ONLINE_JUDGE
  9.         freopen("input.txt", "r", stdin);
  10.         freopen("output.txt", "w", stdout);
  11.     #endif
  12.  
  13.     string str;
  14.     while(cin >> str and str[0]!='#')
  15.     {
  16.         vector <char> r,o,y,g,b;
  17.         if(str[0]!='e')
  18.         {
  19.             for(int i=0;i<str.size();i+=4)
  20.             {
  21.                 if(str[i]=='r')
  22.                     r.push_back(str[i+2]);
  23.                 if(str[i]=='o')
  24.                     o.push_back(str[i+2]);
  25.                 if(str[i]=='y')
  26.                     y.push_back(str[i+2]);
  27.                 if(str[i]=='g')
  28.                     g.push_back(str[i+2]);
  29.                 if(str[i]=='b')
  30.                     b.push_back(str[i+2]);
  31.             }
  32.         }
  33.         if(str[0]=='e')
  34.         {
  35.             vector <int> changes;
  36.             int lim = r.size(); //every vector size same
  37.             for(int i=0;i<lim;i++)
  38.             {
  39.                 int cnt=0;
  40.                 for(int j=0;j<lim;j++)
  41.                     if(i!=j)
  42.                         if(r[i]!=r[j])
  43.                             cnt++;
  44.  
  45.                 for(int j=0;j<lim;j++)
  46.                     if(i!=j)
  47.                         if(o[i]!=o[j])
  48.                             cnt++;
  49.  
  50.                 for(int j=0;j<lim;j++)
  51.                     if(i!=j)
  52.                         if(y[i]!=y[j])
  53.                             cnt++;
  54.  
  55.                 for(int j=0;j<lim;j++)
  56.                     if(i!=j)
  57.                         if(g[i]!=g[j])
  58.                             cnt++;
  59.  
  60.                 for(int j=0;j<lim;j++)
  61.                     if(i!=j)
  62.                         if(b[i]!=b[j])
  63.                             cnt++;
  64.  
  65.                 changes.push_back(cnt);
  66.             }
  67.             int mn=1e7;
  68.             //minimum number of changes
  69.             for(int i=0;i<changes.size();i++)
  70.                 if(changes[i]<mn)
  71.                     mn = changes[i];
  72.             //city that changed minimum according to the statement
  73.             for(int i=0;i<changes.size();i++)
  74.                 if(changes[i]==mn)
  75.                     cout << i+1 << endl;
  76.         }
  77.     }
  78.    
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement