您的位置:首页 > 其它

<NOIP> 21 . P1914 小书童——密码

2017-06-30 16:05 381 查看
题解:这是洛谷的第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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: