NYOJ 594 还是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 main()
{
	int i,j,k,sum,a;
	char str[30],ch[15],pt[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
	while(gets(str))  // gets()函数输入的字符串允许带空格
	{
		sum=0;
		for(i=0;str[i]!='=';i++)
		{
			if(str[i]==' ')
				continue;
			if(str[i]>='a'&&str[i]<='z')
			{
				j=0;
				a=0;
				while((str[i]>='a'&&str[i]<='z'))
				{
					ch[j]=str[i];
					i++;
					j++;
					if(str[i]==' ')
					{
						ch[j]='\0';    // 不要忘记在字符串末尾置'\0';
						for(k=0;k<10;k++)
						{
							if(strcmp(ch,pt[k])==0)// 字符串比较函数
							{
								a=a*10+k;
							}
						}
						j=0;
						i++;
					}
				}
				sum+=a;
			}
			if(str[i]=='=')
				break;
		}
		printf("%d\n",sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值