ZOJ 2971 Give Me the Number

本文介绍了一种将英文书写的数字转换为阿拉伯数字的方法。针对不同的数字范围(如小于20、小于100等),文章详细解释了其书写规则,并提供了一个具体的实现示例。

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

Give Me the Number

Time Limit:2 Seconds     Memory Limit: 65536 KB

Numbers in English are written down in the following way (only numbers lessthan 109 are considered). Numberabc,def,ghi is written as "[abc] million[def] thousand [ghi]".Here "[xyz] " means the written down numberxyz .

In the written down number the part "[abc] million" is omitted ifabc = 0 , "[def] thousand" is omitted ifdef = 0 , and "[ghi] " is omitted if ghi = 0 . If the whole number is equal to0 it is written down as "zero".Note that words "million" and "thousand" are singulareven if the number of millions or thousands respectively is greater than one.

Numbers under one thousand are written down in the following way. The numberxyz is written as "[x] hundred and[yz] ”. ( If yz = 0 it should be only “[x] hundred”. Otherwise if y = 0 it should be only “[x] hundred and [z]”.) Here "[x] hundred and"is omitted ifx = 0 . Note that "hundred" is also always singular.

Numbers under 20 are written down as "zero", "one", "two", "three", "four", "five", "six","seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen", "eighteen", and "nineteen"respectively. Numbers from20 to 99 are written down in the following way.Number xy is written as "[x0] [y] ", and numbers divisible by tenare written as "twenty", "thirty", "forty", "fifty", "sixty", "seventy","eighty", and "ninety" respectively.

For example, number 987,654,312 is written down as "nine hundred andeighty seven million six hundred and fifty four thousand three hundred and twelve",number100,000,037 as "one hundred million thirty seven", number 1,000as "one thousand". Note that "one" is never omitted for millions,thousands and hundreds.

Give you the written down words of a number, please give out the original number.

Input

Standard input will contain multiple test cases. The first line of the input is a single integerT (1 <=T <= 1900) which is the number of test cases. It will be followed by T consecutive test cases.

Each test case contains only one line consisting of a sequence of English words representing a number.

Output

For each line of the English words output the corresponding integer in a single line.You can assume that the integer is smaller than109.

Sample Input

3
one
eleven
one hundred and two

Sample Output

1
11
102
一道模拟。题目意思很简单就是吧英文数字变成阿拉伯的,拿到题目我就想啊直接写个函数就ok结果吧,吃了英语不好的亏英语里面数字是这样的

十 ten 
百 hundred
千 thousand
万 ten thousand
十万 hundred thousand
百万 million
千万 ten million
十亿 billion

也就是说  
thousand==1000
million==1000000
出现这两位了说明该分开存了。有兴趣可以试试吧中文数字变成阿拉伯数字的哈哈哈
#include<bits/stdc++.h>
using namespace std;
int numb(string a)
{
	int k=0,i;
	string b[9]={"one","two","three","four","five","six","seven","eight","nine"};
	string c[9]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
	string d[9]={"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"} ;
	if(a=="zero")k==0;
	else
	for(i=0;i<9;i++)
	{
		if(a==b[i])k=i+1;
		else if(a==c[i])k=10+(i+1);
		else if(a==d[i])k=10*(i+1);
	}
	return k;
} 
int main()
{
	int n,i,a,b,c;
	string s;
	string f;
	scanf("%d",&n);
	getchar(); 
	while(n--)
	{
		getline(cin,s);
		a=0;b=0;c=0;
		s.push_back(' ');
		for(i=0;i<s.size();i++)
		{
			if(s[i]==' ')
			{
			if(f=="hundred")
			a=a*100;
			else if	(f=="thousand")
			{b=a*1000;a=0;}
			else if(f=="million")
			{c=a*1000000;a=0;}
			else {a=a+numb(f);}
			f.clear();continue;}//f=shu(l);ss.push_back(l);l.clear();f.clear()}numb(f);ss.push_back(f);
			f=f+s[i];
		}
		printf("%d\n",a+b+c);		
	}
}


内容概要:本文档提供了关于“微型车间生产线的设计与生产数据采集试验研究”的毕业设计复现代码,涵盖从论文结构生成、机械结构设计、PLC控制系统设计、生产数据采集与分析系统、有限元分析、进度管理、文献管理和论文排版系统的完整实现。通过Python代码和API调用,详细展示了各个模块的功能实现和相互协作。例如,利用SolidWorks API设计机械结构,通过PLC控制系统模拟生产流程,使用数据分析工具进行生产数据的采集和异常检测,以及利用进度管理系统规划项目时间表。 适合人群:具有机械工程、自动化控制或计算机编程基础的学生或研究人员,尤其是从事智能制造领域相关工作的人员。 使用场景及目标:①帮助学生或研究人员快速搭建和理解微型车间生产线的设计与实现;②提供完整的代码框架,便于修改和扩展以适应不同的应用场景;③作为教学或科研项目的参考资料,用于学习和研究智能制造技术。 阅读建议:此资源不仅包含详细的代码实现,还涉及多个学科领域的知识,如机械设计、电气控制、数据分析等。因此,在学习过程中,建议读者结合实际操作,逐步理解每个模块的功能和原理,并尝试调整参数以观察不同设置下的系统表现。同时,可以参考提供的文献资料,深入研究相关理论和技术背景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值