洛谷P1617 爱与愁的一千个伤心的理由

写在前面的话

题目标题和题面啥关系没有。。。。。。。

题目

题目简介:输入一个数(<=9999),输出英文写法。

分析

裸模拟。
所有的裸模拟:考察代码能力,毫无思维难度。。。
所以调了一个多小时。。。。。。。
分情况:
一位数
两位数
整十
十几
其他
三位数
整百
整十
几百零几
几百一十几
几百几十几
四位数
整千
整百
整十
十位个位<20
然后就是写代码。。。。。。。
上代码(一如既往的奇丑码风)
#include <cstdio>
#include <cstring>
#include <iostream>

using std::string;
using std::cout;
using std::cin;

string c[10000];

int len;
int num;
int num2;

int br[10];

namespace LYD
{
	void start()
	{
		c[0] = "zero";
		c[1] = "one";
		c[2] = "two";
		c[3] = "three";
		c[4] = "four";
		c[5] = "five";
		c[6] = "six";
		c[7] = "seven";
		c[8] = "eight";
		c[9] = "nine";
		c[10] = "ten";
		c[11] = "eleven";
		c[12] = "twelve";
		c[13] = "thirteen";
		c[14] = "fourteen";
		c[15] = "fifteen";
		c[16] = "sixteen";
		c[17] = "seventeen";
		c[18] = "eighteen";
		c[19] = "nineteen";
		c[20] = "twenty";
		c[30] = "thirty";
		c[40] = "forty";
		c[50] = "fifty";
		c[60] = "sixty";
		c[70] = "seventy";
		c[80] = "eighty";
		c[90] = "ninety";
		c[100] = "hundred";
		c[1000] = "thousand";
	}
}

int main()
{
	using namespace LYD;

	start();

	scanf("%d", &num);

	num2 = num;

	while(1)
	{
		len++;

		num2 /= 10;

		if(num2 == 0)
			break;
	}

	num2 = num;

	for(int i = len; i >= 1; i--)
	{
		br[i] = num2 % 10;

		num2 /= 10;
	}

	if(len == 1)
		cout << c[num];

	if(len == 2)
	{
		if(num%10 == 0)
			cout << c[num];

		else
		{
			if(num >= 20)
				cout << c[br[1] * 10] << " " << c[num % 10];

			else
				cout << c[num];
		}
	}

	num2 = num;

	if(len == 3)
	{
		cout << c[br[1]] << " " << c[100] << " ";

		if(br[2] == 0 && num % 100 != 0)
		{
			cout << "and" << " " << c[br[3]] << " ";

			return 0;
		}

		if(num2 % 100 >= 10)
		{
			num2 %= 100;

			if(num2 % 10 == 0 || num2 <= 20)
			{
				cout << c[num2] << " ";

				return 0;
			}

			else
				cout << c[br[2] * 10] << " " << c[br[3]] << " ";
		}
	}

	if(len == 4)
	{
		cout << c[br[1]] << " " << c[1000] << " ";

		if(num % 1000 == 0)
			return 0;

		if(br[2] != 0)
		{
			cout << c[br[2]] << " " << c[100] << " ";

			if(br[3] == 0 && br[4] != 0)
			{
				cout << "and" << " " << c[br[4]] << " ";

				return 0;
			}

			if(br[3] != 0 && br[4] == 0)
			{
				cout << c[br[3] * 10] << " ";

				return 0;
			}

			if(br[3] != 0 && br[4] != 0)
			{
				if(br[3] <= 2)
				{
					cout << c[br[3] * 10 + br[4]] << " ";

					return 0;
				}

				else
				{
					cout << c[br[3] * 10] << " " << c[br[4]] << " ";

					return 0;
				}
			}
		}

		if(br[2] == 0)
		{
			cout << "and" << " ";

			if(br[3] <= 2)
			{
				cout << c[br[3] * 10 + br[4]] << " ";

				return 0;
			}

			else
			{
				cout << c[br[3]*10] << " " << c[br[4]] << " ";

				return 0;
			}
		}
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值