#include <bits/stdc++.h>
usingnamespace std;
int main ()
{
int n;
string let;
cin >> n;
cin >> let;
vector<char> v;
for (int i = 0; let[i] != '\0'; i++)
v.push_back(let[i]);
int p = 0;
for (int t = 0; t < v.size(); t++)
{
for (int a = 0; a < n; a++)
v[t] ++;
for (int p = 0; v[t] > 'z'; p++)
v[t] = v[t] - 1;
v[t] -= p;
}
for (int a = 0; a < v.size(); a++)
{
cout << v[a];
}
return 0;
}
If the letter reaches z, it is supposed to start decrementing itself, so I think I have found a way to do it. However when I try it, instead of printing out the correct result, it prints out something different. How can I fix this code?
Example:
Input: 1 z
Output: y
use std::getline() for std::string input to accommodate white-space let[i] != '\0'
unlike a C-string a std::string is not null-terminated, so this condition might never be satisfied
That still doesn't help, I need you to modify the code so that it works, as for the site the first one gives out a problem with the page so I think it is the incorrect link, I can't open it.