| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
居然还有水题,其实这个位移可以稍稍借用下补码的思想,帖下~#include<iostream>
#include<string>
using namespace std;
char shift(char x)
{
return (x - 'A' + 21) % 26 + 'A'; //21 = 26 - 5
}
int main()
{
string a,b,c;
while(cin >> a && a != "ENDOFINPUT")
{
string s;
cin.ignore(1000,'\n');
getline(cin,s);
for(int i = 0; i < s.length(); i++)
{
if(s[i] - 'A' >= 0 && s[i] - 'A' <= 25)
s[i] = shift(s[i]);
}
cin >> c;
for(int i = 0; i < s.length(); i++)
cout << s[i];
cout << endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator