Advertisement
Ritam_C

uri 1298

Jan 13th, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pb push_back
  5. #define p_b pop_back
  6. using namespace std;
  7.  
  8. struct jersey{
  9.     string name;
  10.     string color;
  11.     string size;
  12. };
  13.  
  14. int comp(string a, string b){
  15.     if(a == "P" && (b == "M" || b == "G")){
  16.         return 0;
  17.     } else if(a == "M" && b == "G"){
  18.         return 0;
  19.     } else if(a == b){
  20.         return 2;
  21.     } else{
  22.         return 1;
  23.     }
  24. }
  25.  
  26. int main(){
  27.     ios_base::sync_with_stdio(false);
  28.     cin.tie(NULL);
  29.    
  30.     int flag = 0;
  31.     while(true){
  32.         int n;
  33.         cin >> n;
  34.         if(n == 0){
  35.             break;
  36.         }
  37.  
  38.         if(flag == 1){
  39.             cout << "\n";
  40.         }
  41.         vector<jersey> v;
  42.         for(int i = 0; i < n; i++){
  43.             cin.ignore(1, '\n');
  44.             jersey x;
  45.             getline(cin, x.name);
  46.             cin >> x.color >> x.size;
  47.             v.pb(x);
  48.         }
  49.  
  50.         for(int i = 1; i < n; i++){
  51.             for(int j = 0; j < n-i; j++){
  52.                 if(v[j].color > v[j+1].color){
  53.                     swap(v[j], v[j+1]);
  54.                 } else if(v[j].color == v[j+1].color){
  55.                     if(comp(v[j].size, v[j+1].size) == 1){
  56.                         swap(v[j], v[j+1]);
  57.                     } else if(comp(v[j].size, v[j+1].size) == 2){
  58.                         if(v[j].name > v[j+1].name){
  59.                             swap(v[j], v[j+1]);
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.        
  66.         for(int i = 0; i < n; i++){
  67.             cout << v[i].color << " " << v[i].size << " " << v[i].name << "\n";
  68.         }
  69.         flag = 1;
  70.     }
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement