nyoj594还是A+B

还是A+B

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 1

描述
输入两个小于100的正整数A和B,输出A+B;
A,B均为每位数字对应的英文字母,结果为十进制数。
输入
A,B。
输出
A+B;
样例输入
one + two =
one + two zero =
样例输出
3
21
 
    
 
    
//AC:

/*#include<stdio.h>
#include<string.h>
int fun(char str[20])
{
	if(strcmp(str,"zero")==0) return 0;
	if(strcmp(str,"one")==0) return 1;
	if(strcmp(str,"two")==0) return 2;
	if(strcmp(str,"three")==0) return 3;
	if(strcmp(str,"four")==0) return 4;
	if(strcmp(str,"five")==0) return 5;
	if(strcmp(str,"six")==0) return 6;
	if(strcmp(str,"seven")==0) return 7;
	if(strcmp(str,"eight")==0) return 8;
	if(strcmp(str,"nine")==0) return 9;
}
int main()
{
	//int x,y;
	char str1[20];
	while(scanf("%s",str1)!=EOF)
	{
		int x,y;
		char str2[20],str3[20],str4[20],str5[20],str6[20];
		x=fun(str1);
		scanf("%s",str2);
		if(strcmp(str2,"+")!=0)
		{
			x=fun(str2)+x*10;
			scanf("%s",str3);
			scanf("%s",str4);
			y=fun(str4);
			scanf("%s",str5);
			if(strcmp(str5,"=")!=0)
			{
				y=fun(str5)+y*10;
				scanf("%s",str6);
				printf("%d\n",x+y);
			}
			else 
			printf("%d\n",x+y);
		}
		else
		{
			scanf("%s",str3);
			y=fun(str3);
			scanf("%s",str4);
			if(strcmp(str4,"=")==0)
			{
				printf("%d\n",x+y);
			}
			else
			{
				y=fun(str4)+y*10;
				scanf("%s",str5);
				printf("%d\n",x+y);
			}
		}
	}
	return 0;
}*/

//AC:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int fun(char str[20])
{
	if(strcmp(str,"zero")==0) return 0;
	if(strcmp(str,"one")==0) return 1;
	if(strcmp(str,"two")==0) return 2;
	if(strcmp(str,"three")==0) return 3;
	if(strcmp(str,"four")==0) return 4;
	if(strcmp(str,"five")==0) return 5;
	if(strcmp(str,"six")==0) return 6;
	if(strcmp(str,"seven")==0) return 7;
	if(strcmp(str,"eight")==0) return 8;
	if(strcmp(str,"nine")==0) return 9;
}
int main()
{
	char str1[20];
	while(scanf("%s",str1)!=EOF)
	{
		char str2[20],str3[20],str4[20],str5[20],str6[20];
		int x,y;
		x=fun(str1);
		cin>>str2;
		if(strcmp(str2,"+")!=0)
		{
			x=fun(str2)+x*10;
			cin>>str3;
			//y=fun(str3);
			cin>>str4;
			y=fun(str4);
			cin>>str5;
			if(strcmp(str5,"=")!=0)
			{
				cin>>str6;
				y=fun(str5)+y*10;
				cout<<x+y<<endl;
			}
			else
			cout<<x+y<<endl;
		}
		else
		{
			cin>>str3;
			y=fun(str3);
			cin>>str4;
			if(strcmp(str4,"=")==0)
			cout<<x+y<<endl;
			else
			{
				y=fun(str4)+y*10;
				cin>>str5;
				cout<<x+y<<endl;
			}
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值