写在前面的话
题目标题和题面啥关系没有。。。。。。。
题目
题目简介:输入一个数(<=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;
}