输出下一字母

来源:互联网 发布:流星网络电视手机版 编辑:程序博客网 时间:2024/05/17 02:12

Description

输入一行电报文字,将字母变成其下一字母(如’a’变成’b’……’z’变成’a’其它字符不变)。

Input

一行字符

Output

加密处理后的字符

Sample Input

a b

Sample Output

b c

HINT


#include <iostream>
#include <cstdio> //gets输入,用到的头文件,每次都忘记....
#include <cstring>
usingnamespace std;
intmain()
{
    charstr[1001],c;
    inti,n;
    gets(str);
    n=strlen(str); //计算字符串长度
    for(i=0;i<n;i++)
    {
        if(str[i]>='a'&&str[i]<='y'||str[i]>='A'&&str[i]<='Y')
        {
            c=str[i]+1;
            cout<<c;
        }
        elseif(str[i]=='z'||str[i]=='Z') //当输入字符为z or Z 时,转换为a or A
        {
            c=str[i]-25;
            cout<<c;
        }
        elsecout<<str[i];
    }
    cout<<endl;
    return0;
}
 
/**************************************************************
    Problem: 1062
    User: 201358501133
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1268 kb
****************************************************************/


0 0
原创粉丝点击