Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <unordered_set>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. ifstream in("zimeria.in");
  9. ofstream out("zimeria.out");
  10.  
  11. const int ORDER_LENGTH = 13;
  12. const int LENGTH = 5;
  13. const int base = 27;
  14. const int nMax = 400005;
  15.  
  16. struct str
  17. {
  18.     char c[LENGTH + 1];
  19. };
  20.  
  21. int p, n;
  22. char order[ORDER_LENGTH];
  23. char cuvant[LENGTH + 1];
  24. str v[nMax];
  25. char complexity['z' + 1];
  26. char charName[30];
  27.  
  28. void rez1()
  29. {
  30.     unordered_set<unsigned long long> ap;
  31.     unsigned long long Hash;
  32.     int rasp = 0;
  33.     for(int i = 1; i <= n; ++i)
  34.     {
  35.         in >> cuvant;
  36.         Hash = 0;
  37.         for(int j = 0; j < LENGTH; ++j)
  38.             Hash = Hash * base + cuvant[j];
  39.         if(ap.find(Hash) == ap.end())
  40.         {
  41.             ap.insert(Hash);
  42.             rasp++;
  43.         }
  44.     }
  45.     out << rasp;
  46. }
  47.  
  48. bool cmp(const str &a, const str &b)
  49. {
  50.     for(int i = 0; i < LENGTH; ++i)
  51.     {
  52.         if(a.c[i] < b.c[i])
  53.             return true;
  54.         else if(a.c[i] > b.c[i])
  55.             return false;
  56.     }
  57.     return true;
  58. }
  59.  
  60. void rez2()
  61. {
  62.     for(int i = 0; i < ORDER_LENGTH; ++i)
  63.     {
  64.         complexity[order[i]] = 'a' + i;
  65.         charName['a' + i] = order[i];
  66.     }
  67.     for(int i = 1; i <= n; ++i)
  68.     {
  69.         in >> cuvant;
  70.         for(int j = 0; j < LENGTH; ++j)
  71.             v[i].c[j] = complexity[cuvant[j]];
  72.     }
  73.     sort(v + 1, v + n + 1, cmp);
  74.     for(int i = 1; i <= n; ++i)
  75.     {
  76.         for(int j = 0; j < LENGTH; ++j)
  77.             out << charName[v[i].c[j]];
  78.         out << "\n";
  79.     }
  80. }
  81.  
  82. int main()
  83. {
  84.     in >> p >> n;
  85.     in >> order;
  86.     if(p == 1)
  87.         rez1();
  88.     else
  89.         rez2();
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement