九度:1010

浙大2005年研究生机试


此为模拟类型的题目。A+B

#include <iostream>
#include <string>

using namespace std;

int trans(string s){
	if("one" == s) return 1;
	else if("two" == s) return 2;
	else if("three" == s) return 3;
	else if("four" == s) return 4;
	else if("five" == s) return 5;
	else if("six" == s) return 6;
	else if("seven" == s) return 7;
	else if("eight" == s) return 8;
	else if("nine" == s) return 9;
	else return 0;
}

int main(){
#ifdef ONLINE_JUDGE
#else
    freopen("E:\\in.txt", "r", stdin);
#endif

	string s;
	while(cin>>s){
		int a, b;
		for(a=trans(s); cin>>s, s != "+"; a=a*10 + trans(s));
		for(b=0; cin>>s, s!= "="; b=b*10 +trans(s));
		int c = a+b;
		if(c == 0)
			break;
		else
			cout << c << endl;
	}

	return 0;

}


#include <stdio.h>
#include <string.h>

const int MAXSIZE = 20;
 
void turn(int & t, char str[]){
    if(strcmp(str, "one") == 0){
        t = 1;
    }else if(strcmp(str, "two") == 0){
        t = 2;
    }else if(strcmp(str, "two") == 0){
        t = 2;
    }
    else if(strcmp(str, "three") == 0){
        t = 3;
    }
    else if(strcmp(str, "four") == 0){
        t = 4;
    }
    else if(strcmp(str, "five") == 0){
        t = 5;
    }
    else if(strcmp(str, "six") == 0){
        t = 6;
    }
    else if(strcmp(str, "seven") == 0){
        t = 7;
    }
    else if(strcmp(str, "eight") == 0){
        t = 8;
    }else if(strcmp(str, "nine") == 0){
        t = 9;
    }
    else if(strcmp(str, "zero") == 0){
        t = 0;
    }
    return ;
}
 
int main(){
 
#ifdef ONLINE_JUDGE
#else
    freopen("E:\\in.txt", "r", stdin);
#endif
 
    char str[MAXSIZE];
    while( scanf("%s" ,str) != EOF){
        int a=0;
        int t;
        turn(t, str);
        a = a*10 + t;
        while(scanf("%s", str) && strcmp(str, "+") != 0){
            turn(t, str);
            a = a*10 + t;
        }// read a
        int b=0;
        while(scanf("%s", str) && strcmp(str, "=") != 0){
            turn(t, str);
            b = b*10 + t;
        }// read b
 
        int c = a +b;
        if(c != 0){
            cout << a+b << endl;
        }else{
            break;
        }
    }//while
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值