Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- /*
- char lex[] =
- {'A',
- 'a',
- 'B',
- 'b',
- 'C',
- 'c',
- 'D',
- 'd',
- 'E',
- 'e',
- 'F',
- 'f',
- 'G',
- 'g',
- 'H',
- 'h',
- 'I',
- 'i',
- 'J',
- 'j',
- 'K',
- 'k',
- 'L',
- 'l',
- 'M',
- 'm',
- 'N',
- 'n',
- 'O',
- 'o',
- 'P',
- 'p',
- 'Q',
- 'q',
- 'R',
- 'r',
- 'S',
- 's',
- 'T',
- 't',
- 'U',
- 'u',
- 'V',
- 'v',
- 'W',
- 'w',
- 'X',
- 'x',
- 'Y',
- 'y',
- 'Z',
- 'z'};
- */
- bool cmp(string s1, string s2)
- {
- for (int i = 0; i < min(s1.length(), s2.length()); i++)
- {
- char x = s1[i];
- char y = s2[i];
- if (isupper(x) && islower(y))
- {
- if (x == toupper(y))) return; //A -> a or B->b
- else
- return; //a->A or b->B
- }
- else if (isupper(x) && isupper(y))
- {
- if (x < y) return; //A -> B
- else
- return; //B->A
- }
- else if (islower(x) && islower(y))
- {
- if (x < y)
- return; //a->b
- else return; //b->a
- }
- else if (islower(x) && islower(y))
- {
- if(x == y) return; //a -> a or b-> b
- }
- }
- if (s1.length() > s2.length())
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- int main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- cin >> n;
- string dictionary[n];
- for (int i = 0; i < n; i++)
- {
- string s;
- cin >> s;
- dictionary[i] = s;
- }
- sort(dictionary, dictionary + n, cmp);
- //Testing
- cout << endl;
- for (int i = 0; i < n; i++)
- {
- cout << dictionary[i] << endl;
- }
- //Query
- int q;
- cin >> q;
- getchar();
- while (q--)
- {
- string que;
- getline(cin, que);
- for (int z = 0; z < n; z++)
- {
- if (que[0] == dictionary[z][0])
- {
- cout << dictionary[z] << endl;
- dictionary[z] = "0";
- break;
- }
- else if (z == n - 1)
- cout << "Already Mastered" << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement