栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

这道题的题目?

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

这道题的题目?

大家好,我是大白,一位小学森

是不是感觉少了什么

以后开头就这个了

这道题叫“爱与愁的一千个伤心的理由”

这题目,绝了

开始吧

题目懒得说

上代码

#include
using namespace std;
const string num[11] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
const string ty[11] = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
const string teen[21] = {"", "", "", "", "", "", "", "", "", "", "", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
int a[5], n, cnt;
int main(){	
	cin>>n;
	int tmp = n;
	while(tmp) {
		a[++cnt] = tmp % 10;
		tmp /= 10;
	}
	int teens = a[2] * 10 + a[1];
	if(cnt == 4) {
		cout << num[a[4]] << ' ';printf("thousand");
		if(a[1] == 0 && a[2] == 0 && a[3] == 0)
			return 0;
		else if(a[3] == 0 && a[2] && a[1]) {
			putchar(' ');
			if(teens >= 11 && teens <= 19) {
				cout << teen[teens];
				return 0;
			}
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << "and " << ty[a[2]];
			putchar(' ');
			cout << num[a[1]];
		} else if(a[3] && !a[2] && a[1]){
			putchar(' ');
			cout << num[a[3]];
			printf(" hundred and ");
			cout << num[a[1]];
		} else if(a[3] && a[2] && !a[1]) {
			putchar(' ');
			cout << num[a[3]];
			printf(" hundred ");
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << ty[a[2]];
		} else if(a[3] && !a[2] && !a[1]) {
			cout << ' ' << num[a[3]];
			printf(" hundred");
		}
		else if(!a[3] && a[2] && !a[1]) {
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << ty[a[2]];
		}
		else if(!a[3] && !a[2] && a[1])
			cout << " and " << num[a[1]];
		else {
			cout << ' ' << num[a[3]] << " hundred ";
			if(teens >= 11 && teens <= 19)
				cout << teen[teens];
			else {
				cout << ty[a[2]] << ' ' << num[a[1]];
			}
		}  
	} else if(cnt == 3) {
		cout << num[a[3]]; printf(" hundred");
		if(!a[2] && !a[1])	return 0;
		else if(a[2] && !a[1]) {
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << ty[a[2]];
		}
		else if(!a[2] && a[1]) {
			printf(" and ");
			cout << num[a[1]];
		} else if(teens < 11 || teens > 19) {
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << ty[a[2]];
			cout << ' ' << num[a[1]];
		} else
			cout << ' ' << teen[teens];
	} else if(cnt == 2) {
		if(teens >= 11 && teens <= 19)
			cout << teen[teens];
		else if(!a[1]) {
			if(a[2] == 1)	cout << " and " << ty[1];
			else	cout << ty[a[2]];
		}
		else
			cout << ty[a[2]] << ' ' << num[a[1]];
	} else
		cout << num[a[1]];
	return 0;
}

我是大白,每日一更,记得关注!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/629452.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号