• Source
    1. #include <iostream>
    2. #include <string>
    3. using namespace std;
    4.  
    5. int main() {
    6. string s;
    7. int n,k;
    8. cin>>n;
    9. cin>>s;
    10. cin>>k;
    11. for(int i = 0; i < s.size(); ++i){
    12. if( (s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <='Z')){
    13. bool lowered = false;
    14. if( isupper(s[i])){
    15. s[i] = tolower(s[i]);
    16. lowered = true;
    17. }
    18.  
    19. int num = static_cast<int>(s[i] - 'a');
    20. num += k;
    21. if( num < 0){
    22. num += 26;
    23. }
    24. if( num >= 26){
    25. num -= 26;
    26. }
    27. char res = static_cast<char>(num + 'a');
    28. s[i] = res;
    29. if( lowered){
    30. s[i] = toupper(s[i]);
    31. }
    32. }
    33. }
    34. cout<<s;
    35. // your code goes here
    36. return 0;
    37. }