2005年第1题

本文介绍了一个使用C语言编写的程序,该程序能够将英文单词形式的数字转换为阿拉伯数字,并进行加法运算。通过输入特定的英文数字词汇,程序会解析并计算出相应的数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

地址:http://ac.jobdu.com/problem.php?pid=1010

C语言源码:

#include<stdio.h>
#include<string.h>
int main()
{
	char S[100];
	int a,b;
	a=1;
	b=1;
	while(a!=0||b!=0)
	{
		a=0;
		b=0;
		scanf("%s",S);
		getchar();
		while(strcmp(S,"+")!=0)
		{
			a=a*10;
			if(strcmp(S,"one")==0)
				a=a+1;
			else
				if(strcmp(S,"two")==0)
					a=a+2;
				else
					if(strcmp(S,"three")==0)
						a=a+3;
					else
						if(strcmp(S,"four")==0)
							a=a+4;
						else
							if(strcmp(S,"five")==0)
								a=a+5;
							else
								if(strcmp(S,"six")==0)
									a=a+6;
								else
									if(strcmp(S,"seven")==0)
										a=a+7;
									else
										if(strcmp(S,"eight")==0)
											a=a+8;
										else
											if(strcmp(S,"nine")==0)
												a=a+9;
			scanf("%s",S);
			getchar();
		}
		while(strcmp(S,"=")!=0)
		{
			b=b*10;
			if(strcmp(S,"one")==0)
				b=b+1;
			else
				if(strcmp(S,"two")==0)
					b=b+2;
				else
					if(strcmp(S,"three")==0)
						b=b+3;
					else
						if(strcmp(S,"four")==0)
							b=b+4;
						else
							if(strcmp(S,"five")==0)
								b=b+5;
							else
								if(strcmp(S,"six")==0)
									b=b+6;
								else
									if(strcmp(S,"seven")==0)
										b=b+7;
									else
										if(strcmp(S,"eight")==0)
											b=b+8;
										else
											if(strcmp(S,"nine")==0)
												b=b+9;
			scanf("%s",S);
			getchar();
		}
		if(a!=0||b!=0)
			printf("%d\n",a+b);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值