调用strcmp函数
两个字符 str1 和 str2 (比较的是字典序)
如果 str1 = str2 ,返回值为0;
如果 str1 > str2 ,返回值为正;
如果 str1 < str2 ,返回值为负;
代码如下:
#include<iostream>
#include<cstring>
using namespace std;
char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int com(char s[]){
for(int i=0;i<10;i++)
if(strcmp(s,num[i])==0)
return i;
}
int main(){
int a,b;
char s[6];
while(cin>>s){
a=0;
b=0;
while(strcmp(s,"+")!=0){
a=a*10+com(s);
cin>>s;
}
cin>>s;
while(strcmp(s,"=")!=0){
b=b*10+com(s);
cin>>s;
}
if(a+b==0) break;
cout<<a+b<<endl;
}
return 0;
}