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

HDOJ_1228_A+B

时间:2018-11-30 22:36:10      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:def   close   return   break   a+b   c代码   txt   pac   iostream   

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#define Max 105
using namespace std;
int main(void)
{
    freopen("in.txt","r",stdin);
    int i,j,sum1,sum2,flag,a,len;
    char s[Max],s1[Max];
    while(gets(s)!=NULL)
    {
        len=strlen(s);
        sum1=sum2=0;
        flag=0;
        for(i=0,j=0;i<len;i++)
        {
            if(s[i]>=a&&s[i]<=z)
                s1[j++]=s[i];
            if(s[i]== &&s[i-1]!=+)
            {
                s1[j]=\0;
                if(!strcmp(s1,"zero")) a=0;
                else if(!strcmp(s1,"one")) a=1;
                else if(!strcmp(s1,"two")) a=2;
                else if(!strcmp(s1,"three")) a=3;
                else if(!strcmp(s1,"four")) a=4;
                else if(!strcmp(s1,"five")) a=5;
                else if(!strcmp(s1,"six")) a=6;
                else if(!strcmp(s1,"seven")) a=7;
                else if(!strcmp(s1,"eight")) a=8;
                else if(!strcmp(s1,"nine")) a=9;
                j=0;
                if(!flag)
                    sum1=sum1*10+a;
                else
                    sum2=sum2*10+a;
            }
            else if(s[i]==+)
                flag=1;
        }
        if(sum1==0&&sum2==0)
            break;
        
        printf("%d\n",sum1+sum2);
    }
    
    
    fclose(stdin);
    return 0;
}

 

HDOJ_1228_A+B

标签:def   close   return   break   a+b   c代码   txt   pac   iostream   

原文地址:https://www.cnblogs.com/phaLQ/p/10046658.html

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