假设老王原来一个BBS上的密码为zvbo941987,为了方便记忆,他通过一种算法把这个密码变换成YUANzi1987,这个密码是他的名字和出生年份,怎么忘都忘不了,而且可以明目张胆地放在显眼的地方而不被别人知道真正的密码。 他是这么变换的,大家都知道手机上的字母: 1--1, abc--2, def--3, ghi--4, jkl--5, mno--6, pqrs--7, tuv--8 wxyz--9, 0--0,就这么简单,老王把密码中出现的小写字母都变成对应的数字,数字和其他的符号都不做变换,声明:密码中没有空格,而密码中出现的大写字母则边成小写之后往后移一位,如:X,先边成小写,再往后移一位,不就是y了嘛,简单吧。记住,z往后移是a哦。
#include<iostream>
using namespace std;
int main(){
char a[10];
for (int i = 0; i < 10; i++)
{
cin >> a[i];
}
for (int i = 0; i < 4; i++) {
if (a[i] >= 65 && a[i] < 96)
a[i] += 33;
else if(a[i]=96)
a[i]=97;
}
for(int i=4;i<6;i++){
if (a[i] == 'a' || a[i] == 'b' || a[i] == 'c')
a[i] = '2';
else if (a[i] == 'd' || a[i] == 'e' || a[i] == 'f')
a[i] = '3';
else if (a[i] == 'g' || a[i] == 'h' || a[i] == 'i')
a[i] = '4';
else if (a[i] == 'j' || a[i] == 'k' || a[i] == 'l')
a[i] = '5';
else if (a[i] == 'm' || a[i] == 'n' || a[i] == 'o')
a[i] = '6';
else if (a[i] == 'p' || a[i] == 'q' || a[i] == 'r' || a[i] == 's')
a[i] = '7';
else if (a[i] == 't' || a[i] == 'u' || a[i] == 'v')
a[i] = '8';
else if (a[i] == 'w' || a[i] == 'x' || a[i] == 'y' || a[i] == 'z')
a[i] = '9';
}
for (int i = 0; i < 10; i++){
cout << a[i]; }
return 0;
}