题解:这是洛谷的第21道题目,本题的重点是当字符为‘Z’时,它的下一位是‘A’。
源代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <sstream>
#include <stdlib.h>
using namespace std;
int main()
{
int movenumber;
string password;
char *Realpassword = new char[password.size()];
cin >> movenumber;
cin >> password;
for (size_t i = 0; i < password.size(); i++)
{
int loop = 0;
char c = password[i];
if (c >= 'A'&&c <= 'Z')
{
while (loop < movenumber)
{
if (c == 'Z')
c = 'A';
else
c++;
loop++;
}
}
else if(c >= 'a'&&c <= 'z')
{
while (loop < movenumber)
{
if (c == 'z')
c = 'a';
else
c++;
loop++;
}
}
cout << c;
}
cout << endl;
system("pause");
return 0;
}