码迷,mamicode.com
首页 > 其他好文 > 详细

【转】HDU-1228-A+B: strcmp();

时间:2015-08-09 10:44:20      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

  

【转】HDU-1228-A+B: strcmp();

标签:

原文地址:http://www.cnblogs.com/FightForCMU/p/4714627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!