http://acm.hdu.edu.cn/showproblem.php?pid=1228
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
string str1,str4,strp,str2,str5,stre;
map<string,int>m1;
int num1,num2;
m1["one"]=1,m1["two"]=2,m1["three"]=3,m1["four"]=4,m1["five"]=5;
m1["six"]=6,m1["seven"]=7,m1["eight"]=8,m1["nine"]=9,m1["zero"]=0;
while(cin>>str1>>strp)
{
if(strp!="+")
{
cin>>str4;
num1=m1[str1]*10+m1[strp]; //map的使用
}
else
num1=m1[str1];
cin>>str2>>stre;
if(stre!="=")
{
cin>>str5;
num2=m1[str2]*10+m1[stre];
}
else
num2=m1[str2];
if(num1==0&&num2==0)
break;
cout<<num1+num2<<endl;
}
return 0;
}

本文介绍了一个使用C++编写的程序,该程序能够将英文形式的两位数相加并输出其数值结果。通过预先定义的映射表,程序可以识别如'two'和'three'这样的英文单词,并将其转换为对应的数字进行加法运算。
471

被折叠的 条评论
为什么被折叠?



