AquaBlitz11

[t107] Secret Problem

Oct 9th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1010;
  6.  
  7. int main()
  8. {
  9.     int n, k;
  10.     char s[N];
  11.     scanf("%d%d %s", &n, &k, s);
  12.     k %= 26;
  13.     if (k < 0) k += 26;
  14.  
  15.     for (int i = 0; s[i]; ++i) {
  16.         if (isupper(s[i]))
  17.             s[i] = ((s[i]-'A')+k)%26 + 'A';
  18.         else if (islower(s[i]))
  19.             s[i] = ((s[i]-'a')+k)%26 + 'a';
  20.         printf("%c", s[i]);
  21.     }
  22.  
  23.     return 0;
  24. }
Add Comment
Please, Sign In to add comment