Loading...
Submission
# When Author Problem Language CPU Memory
20868 2024-06-13 22:06:36 AHAMMED_99 Akash and Cipher C++ 14 22 ms 4568 kb Wrong Answer - 4
Test Cases
# CPU Memory Points
1 1 ms 3220 kb 1 Accepted
2 1 ms 3344 kb 1 Accepted
3 1 ms 3232 kb 1 Accepted
4 22 ms 4568 kb 0 Wrong Answer
5 0 ms 0 kb 0 Skipped
6 0 ms 0 kb 0 Skipped
Source Code
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. char shift_char_up(char ch, int shift) {
  8. return 'a' + (ch - 'a' + shift) % 26;
  9. }
  10.  
  11. char shift_char_down(char ch, int shift) {
  12. return 'a' + (ch - 'a' - shift + 26) % 26;
  13. }
  14.  
  15. void decrypt_message(int n, const string& s, const string& q, string& result) {
  16. for (int i = 0; i < n; ++i) {
  17. if (q[i] == 'U') {
  18. result[i] = shift_char_up(s[i], i + 1);
  19. } else if (q[i] == 'D') {
  20. result[i] = shift_char_down(s[i], i + 1);
  21. }
  22. }
  23. }
  24.  
  25. int main() {
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28.  
  29. int T;
  30. cin >> T;
  31.  
  32. vector<string> results;
  33. results.reserve(T);
  34.  
  35. for (int t = 0; t < T; ++t) {
  36. int n;
  37. cin >> n;
  38. string s, q;
  39. cin >> s >> q;
  40.  
  41. string result(n, ' ');
  42. decrypt_message(n, s, q, result);
  43. results.push_back(result);
  44. }
  45.  
  46. for (const auto& result : results) {
  47. cout << result << endl;
  48. }
  49.  
  50. return 0;
  51. }
  52.