Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <unordered_set>
- #include <algorithm>
- using namespace std;
- ifstream in("zimeria.in");
- ofstream out("zimeria.out");
- const int ORDER_LENGTH = 13;
- const int LENGTH = 5;
- const int base = 27;
- const int nMax = 400005;
- struct str
- {
- char c[LENGTH + 1];
- };
- int p, n;
- char order[ORDER_LENGTH];
- char cuvant[LENGTH + 1];
- str v[nMax];
- char complexity['z' + 1];
- char charName[30];
- void rez1()
- {
- unordered_set<unsigned long long> ap;
- unsigned long long Hash;
- int rasp = 0;
- for(int i = 1; i <= n; ++i)
- {
- in >> cuvant;
- Hash = 0;
- for(int j = 0; j < LENGTH; ++j)
- Hash = Hash * base + cuvant[j];
- if(ap.find(Hash) == ap.end())
- {
- ap.insert(Hash);
- rasp++;
- }
- }
- out << rasp;
- }
- bool cmp(const str &a, const str &b)
- {
- for(int i = 0; i < LENGTH; ++i)
- {
- if(a.c[i] < b.c[i])
- return true;
- else if(a.c[i] > b.c[i])
- return false;
- }
- return true;
- }
- void rez2()
- {
- for(int i = 0; i < ORDER_LENGTH; ++i)
- {
- complexity[order[i]] = 'a' + i;
- charName['a' + i] = order[i];
- }
- for(int i = 1; i <= n; ++i)
- {
- in >> cuvant;
- for(int j = 0; j < LENGTH; ++j)
- v[i].c[j] = complexity[cuvant[j]];
- }
- sort(v + 1, v + n + 1, cmp);
- for(int i = 1; i <= n; ++i)
- {
- for(int j = 0; j < LENGTH; ++j)
- out << charName[v[i].c[j]];
- out << "\n";
- }
- }
- int main()
- {
- in >> p >> n;
- in >> order;
- if(p == 1)
- rez1();
- else
- rez2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement