历年上机题----密码翻译

本题其实没啥意义,不过读入一个带有空格的字符串的知识还是需要复习一下。

getline(cin,s);

#include <bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    string s,s1;
    int T;
    // cin>>T;
    // getline(cin,s1);
    while (getline(cin,s))
    {
        //cout<<s<<endl;
        int n=s.size();
        for(int i=0;i<n;i++)
        {
            if(s[i]>='a'&&s[i]<='z')
            {
                if(s[i]=='z') s[i]='a';
                else s[i]=s[i]+1;
            }
            if(s[i]>='A'&&s[i]<='Z')
            {
                if(s[i]=='Z') s[i]='A';
                else s[i]=s[i]+1;
            }
        }
        cout<<s<<endl;
        /* code */
    }
    
    return 0;
}
发布了449 篇原创文章 · 获赞 197 · 访问量 25万+

猜你喜欢

转载自blog.csdn.net/qq_40774175/article/details/105351658