【转】HDU-1228-A+B: strcmp();
C/C++函数,比较两个字符串
设这两个字符串为str1,str2,
若str1==str2,则返回零;
若str1>str2,则返回正数;
若str1<str2,则返回负数。
两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。
#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;
map<string,int>M;
int main()
{
M["zero"]=0;M["one"]=1;M["two"]=2;M["three"]=3;M["four"]=4;M["five"]=5;
M["six"]=6;M["seven"]=7;M["eight"]=8;M["nine"]=9;M["ten"]=10;
while(1)
{
int A=0;
char Str[10];
while(cin>>Str && strcmp(Str,"+"))
{
A=A*10+M[Str];
}
int B=0;
while(cin>>Str && strcmp(Str,"="))
{
B=B*10+M[Str];
}
if( A==0 && B==0 )
break;
else
cout<<A+B<<endl;
}
return 0;
}

浙公网安备 33010602011771号