简单密码.cpp

简单密码

http://www.nowcoder.com/questionTerminal/7960b5038a2142a18e27e4c733855dac

十分简单易懂的代码

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
char UptoLow(char x)
{
    if(x>='A'&&x<='Y')x+=33;
    else if(x=='Z')x='a';
    return x;
}
char Lowtoint(char x)
{
    char ch;
    if(x>='a'&&x<='c')ch='2';
    else if(x>='d'&&x<='f')ch='3';
    else if(x>='g'&&x<='i')ch='4';
    else if(x>='j'&&x<='l')ch='5';
    else if(x>='m'&&x<='o')ch='6';
    else if(x>='p'&&x<='s')ch='7';
    else if(x>='t'&&x<='v')ch='8';
    else ch='9';
    return ch;
}
int main()
{
    string str;
    while(cin>>str)
    {    
        for(int i=0;i<str.size();++i)
        {
            if(str[i]>='A'&&str[i]<='Z')
                str[i]=UptoLow(str[i]);
            else if(str[i]>='a'&&str[i]<='z')
                str[i]=Lowtoint(str[i]);
        }
        cout<<str<<endl;
    }
    return 0;
}
    

全部评论

相关推荐

06-20 21:22
已编辑
门头沟学院 Java
纯真的河老师在喝茶:答应了就跑啊,实习随便跑啊,别被pua了,md就是找个廉价劳动力,还平稳过度正式工,到时候跟你说没转正
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务