题意:
解译密码(即对应的英文字母的转换)
#include<stdio.h>
#include<map>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
char ss[200];
map<char,char>m;
m['A'] = 'V';
m['B'] = 'W';
m['C'] = 'X';
m['D'] = 'Y';
m['E'] = 'Z';
m['F'] = 'A';
m['G'] = 'B';
m['H'] = 'C';
m['I'] = 'D';
m['J'] = 'E';
m['K'] = 'F';
m['L'] = 'G';
m['M'] = 'H';
m['N'] = 'I';
m['O'] = 'J';
m['P'] = 'K';
m['Q'] = 'L';
m['R'] = 'M';
m['S'] = 'N';
m['T'] = 'O';
m['U'] = 'P';
m['V'] = 'Q';
m['W'] = 'R';
m['X'] = 'S';
m['Y'] = 'T';
m['Z'] = 'U';
m[','] = ',';
m[' '] = ' ';
while(cin.getline(ss,200))
{
s=ss;
if(s=="START")continue;
else if(s=="END")continue;
else if(s=="ENDOFINPUT")break;
else
{
for(int i=0;i<s.size();i++)
cout<<m[s[i]];
cout<<endl;
}
}
return 0;
}
【小结】:
1.学到一种新的输入cin.getline(ss,200),包含在头文件<iostream>中的按行读取函数其语法为:cin.getline(字符指针,字符个数N,结束符);
2.熟练了map中的映射关系的应用。