Saleh127

UVA 154

Sep 8th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; while(t--)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll n=0,dis,city,ans=10000,i,j,k;
  11. string a;
  12. char cr[105][8];
  13. map<char,int>x;
  14. x['r']=0;
  15. x['o']=1;
  16. x['y']=2;
  17. x['g']=3;
  18. x['b']=4;
  19. while(cin>>a)
  20. {
  21. if(a[0]=='#') break;
  22. else if(a[0]=='e')
  23. {
  24. for(i=0;i<n;i++)
  25. {
  26. dis=0;
  27. for(j=0;j<n;j++)
  28. {
  29. for(k=0;k<5;k++)
  30. {
  31. if(cr[i][k]!=cr[j][k])
  32. {
  33. dis++;
  34. }
  35. }
  36. }
  37. if(dis<ans)
  38. {
  39. ans=dis;
  40. city=i+1;
  41. }
  42. }
  43. cout<<city<<endl;
  44. ans=10000;
  45. n=0;
  46. }
  47. else
  48. {
  49. cr[n][x[a[0]]]=a[2];
  50. cr[n][x[a[4]]]=a[6];
  51. cr[n][x[a[8]]]=a[10];
  52. cr[n][x[a[12]]]=a[14];
  53. cr[n][x[a[16]]]=a[18];
  54. n++;
  55. }
  56. }
  57. return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment