Codeforces Round #299 (Div. 2)A. Tavas and Nafas点击进入题目页面
A. Tavas and Nafas
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn’t have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without water again, so right now he’s really messed up and can’t think.
Your task is to help him by telling him what to type.
Input
The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas’s score.
Output
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens (‘-‘). Do not use spaces.
Sample test(s)
input
6
output
six
input
99
output
ninety-nine
input
20
output
twenty
Note
You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .
题意:输入1到99,让你输出英文。
题解:请看代码。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
void print_1(int num){
switch(num){
case 0:printf("zero");break;
case 1:printf("one");break;
case 2:printf("two");break;
case 3:printf("three");break;
case 4:printf("four");break;
case 5:printf("five");break;
case 6:printf("six");break;
case 7:printf("seven");break;
case 8:printf("eight");break;
case 9:printf("nine");break;
case 10:printf("ten");break;
case 11:printf("eleven");break;
case 12:printf("twelve");break;
case 13:printf("thirteen");break;
case 14:printf("fourteen");break;
case 15:printf("fifteen");break;
case 16:printf("sixteen");break;
case 17:printf("seventeen");break;
case 18:printf("eighteen");break;
case 19:printf("nineteen");break;
case 20:printf("twenty");break;
case 30:printf("thirty");break;
case 40:printf("forty");break;
case 50:printf("fifty");break;
case 60:printf("sixty");break;
case 70:printf("seventy");break;
case 80:printf("eighty");break;
case 90:printf("ninety");break;
}
}
int main()
{
int s;
scanf("%d",&s);
if(s<=20) {print_1(s);printf("\n");}
else if(s%10==0) {print_1(s);printf("\n");}
else {
print_1(s/10*10);printf("-");print_1(s%10);printf("\n");
}
return 0;
}