//利用数组下标完成密码字符串转换,前面有道字符串转换的题也是这个思路 //对于非字符不识别,等到输出时若为字符输出out_str[i],否则输出原str[i] #include "stdio.h" #include "string" #include "iostream" using namespace std; int main(){ char buf1[10],buf2[10],buf3[300]; string str1,str2,str3,out; char change[27] = "VWXYZABCDEFGHIJKLMNOPQRSTU"; while (getline(cin,str1)){ if (str1 == "ENDOFINPUT") break; getline(cin,str2); getline(cin,str3); out = ""; for (int i = 0; i < str2.size(); ++i) { if (str2[i] >= 'A' && str2[i] <= 'Z') out += change[str2[i]-'A']; } for (int i = 0,j = 0; i < str2.size(); ++i) { if (str2[i] >= 'A' && str2[i] <= 'Z'){ printf("%c",out[j++]); } else{ printf("%c",str2[i]); } } printf("\n"); } }