Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. /*
  5. char lex[] =
  6.     {'A',
  7.      'a',
  8.      'B',
  9.      'b',
  10.      'C',
  11.      'c',
  12.      'D',
  13.      'd',
  14.      'E',
  15.      'e',
  16.      'F',
  17.      'f',
  18.      'G',
  19.      'g',
  20.      'H',
  21.      'h',
  22.      'I',
  23.      'i',
  24.      'J',
  25.      'j',
  26.      'K',
  27.      'k',
  28.      'L',
  29.      'l',
  30.      'M',
  31.      'm',
  32.      'N',
  33.      'n',
  34.      'O',
  35.      'o',
  36.      'P',
  37.      'p',
  38.      'Q',
  39.      'q',
  40.      'R',
  41.      'r',
  42.      'S',
  43.      's',
  44.      'T',
  45.      't',
  46.      'U',
  47.      'u',
  48.      'V',
  49.      'v',
  50.      'W',
  51.      'w',
  52.      'X',
  53.      'x',
  54.      'Y',
  55.      'y',
  56.      'Z',
  57.      'z'};
  58. */
  59. bool cmp(string s1, string s2)
  60. {
  61.     for (int i = 0; i < min(s1.length(), s2.length()); i++)
  62.     {
  63.         char x = s1[i];
  64.         char y = s2[i];
  65.         if (isupper(x) && islower(y))
  66.         {
  67.             if (x == toupper(y))) return; //A -> a or B->b
  68.             else
  69.                 return; //a->A or b->B
  70.         }
  71.         else if (isupper(x) && isupper(y))
  72.         {
  73.             if (x < y) return; //A -> B
  74.             else
  75.                 return; //B->A
  76.         }
  77.         else if (islower(x) && islower(y))
  78.         {
  79.             if (x < y)
  80.                 return; //a->b
  81.             else return; //b->a
  82.         }
  83.         else if (islower(x) && islower(y))
  84.         {
  85.             if(x == y) return; //a -> a or b-> b
  86.         }
  87.     }
  88.     if (s1.length() > s2.length())
  89.     {
  90.         return false;
  91.     }
  92.     else
  93.     {
  94.         return true;
  95.     }
  96. }
  97.  
  98. int main()
  99. {
  100.     int t;
  101.     cin >> t;
  102.     while (t--)
  103.     {
  104.         int n;
  105.         cin >> n;
  106.         string dictionary[n];
  107.         for (int i = 0; i < n; i++)
  108.         {
  109.             string s;
  110.             cin >> s;
  111.             dictionary[i] = s;
  112.         }
  113.  
  114.         sort(dictionary, dictionary + n, cmp);
  115.  
  116.         //Testing
  117.         cout << endl;
  118.         for (int i = 0; i < n; i++)
  119.         {
  120.             cout << dictionary[i] << endl;
  121.         }
  122.  
  123.         //Query
  124.         int q;
  125.         cin >> q;
  126.         getchar();
  127.  
  128.         while (q--)
  129.         {
  130.             string que;
  131.             getline(cin, que);
  132.             for (int z = 0; z < n; z++)
  133.             {
  134.                 if (que[0] == dictionary[z][0])
  135.                 {
  136.                     cout << dictionary[z] << endl;
  137.                     dictionary[z] = "0";
  138.                     break;
  139.                 }
  140.                 else if (z == n - 1)
  141.                     cout << "Already Mastered" << endl;
  142.             }
  143.         }
  144.     }
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement