Advertisement
SorahISA

2019 NHSPC north1 pC

Nov 12th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  5. #define X first
  6. #define Y second
  7. #define Push push_back
  8. #define ALL(x) x.begin(), x.end()
  9.  
  10. using lli = long long;
  11. using pll = pair<lli, lli>;
  12. using Double = long double;
  13. template<typename T>
  14. using Vector = vector<vector<T>>;
  15. template<typename T>
  16. using prior = priority_queue<T>;
  17.  
  18. int main() {
  19.     IOS;
  20.     int n;
  21.     cin >> n;
  22.     getchar();
  23.    
  24.     string s, t;
  25.     getline(cin, s);
  26.     getline(cin, t);
  27.  
  28.     set<char> app;
  29.     string encrypt;
  30.     for (auto x : s) {
  31.         if (x == ' ') continue;
  32.         if (!app.count(x)) {
  33.             app.insert(x);
  34.             encrypt += x;
  35.         }
  36.     }
  37.    
  38.     int tmp = *encrypt.rbegin();
  39.     for (int i = tmp+1; i <= tmp+26; ++i) {
  40.         char j;
  41.         if (i > 'z') j = i - 26;
  42.         else j = i;
  43.        
  44.         if (!app.count(j)) {
  45.             app.insert(j);
  46.             encrypt += j;
  47.         }
  48.     }
  49.    
  50.     assert(encrypt.size() == 26);
  51.    
  52.     string decrypt(26, ' ');
  53.     for (int i = 0; i < 26; ++i) {
  54.         decrypt[encrypt[i] - 'a'] = ('a' + i);
  55.     }
  56.    
  57. //    for (char x = 'a'; x <= 'z'; ++x) cout << x; cout << "\n";
  58. //    cout << encrypt << "\n";
  59.    
  60.     if (n == 1) {
  61.         string answer;
  62.         for (auto x : t) {
  63.             if (x == ' ') {
  64.                 answer += ' ';
  65.                 continue;
  66.             }
  67.             bool big = false;
  68.             if (isupper(x)) {
  69.                 big = true;
  70.                 x += 32;
  71.             }
  72.             answer += (encrypt[x - 'a'] - 32 * big);
  73.         }
  74.        
  75.         cout << answer << "\n";
  76.     }
  77.     if (n == 0) {
  78.         string answer;
  79.         for (auto x : t) {
  80.             if (x == ' ') {
  81.                 answer += ' ';
  82.                 continue;
  83.             }
  84.             bool big = false;
  85.             if (isupper(x)) {
  86.                 big = true;
  87.                 x += 32;
  88.             }
  89.             answer += (decrypt[x - 'a'] - 32 * big);
  90.         }
  91.        
  92.         cout << answer << "\n";
  93.     }
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement