69,112
社区成员




英文翻译自然数
题目描述:按常规英文输出1000以内自然数的英文读法。
输入:每个测试输入包含 1 个测试用例,给出正整数 n(0<= n <1000)
输出:输出占一行:如果 0<= n <1000, 用规定的格式输出 n,所有英文单词小写,最后一个单词后无字符;否则输出ERR。
#include<stdio.h>
int main(){
int x;
scanf("%d",&x);
if(x==0) printf("zero");
if(x>0&&x<1000){
char*a[19]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thriteen","forteen","fifteen","sixteen","seventeen","eighty","nineteen"};
char*b[8]={"twenty","thrity","forty","fifty","sixty","seventy","eighty","ninety"};
if(x/100!=0){ printf("%s",a[(x/100-1)]);
printf(" hundred");
if(x%100<20) printf(" and %s",a[(x%100-1)]) ;
if(x%100>=20) printf(" and %s-%s",b[(x%100/10-2)],a[(x%100%10-1)]);}
if(x/100==0){
if(x<20) printf("%s",a[(x-1)]);
if(x>=20) printf("%s-%s",b[(x%10-2)],a[(x%10%10-1)]);
}}
if(x>=1000||x<0) printf("ERR");}
#include<stdio.h>
void main()
{
char *Eng1[20]={"zero","one","two","three","four","five","six","seven",
"eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen"};
char *Eng2[8]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
int num;
printf("请输入数字: ");
scanf("%d",&num);
printf("对应的英文为: ");
if(num>=0&&num<=19)
printf("%s\n",Eng1[num]);
else if(num<100)
{
int s,y;
s=num/10;
y=num%10;
printf("%s %s\n",Eng2[s-2],Eng1[y]);
}
else if(num<1000)
{
int b,s,y;
b=num/100;
y=num%100;
if(y>9)
{
s=(num%100)/10;
y=(num%100)%10;
if(y==0)
printf("%s hundred and %s\n",Eng1[b],Eng2[s-2]);
else
printf("%s hundred and %s %s\n",Eng1[b],Eng2[s-2],Eng1[y]);
}
else
printf("%s hundred and %s\n",Eng1[b],Eng1[y]);
}
}
#include <stdio.h>
int main() {
int x;
scanf("%d", &x);
if (x < 0 || x >= 1000) {
printf("ERR");
} else if (x == 0) {
printf("zero");
} else {
char *a[19] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
char *b[8] = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
if (x / 100 != 0) {
printf("%s hundred", a[x / 100 - 1]);
if (x % 100 != 0) {
printf(" and ");
if (x % 100 < 20) {
printf("%s", a[x % 100 - 1]);
} else {
printf("%s-%s", b[x % 100 / 10 - 2], a[x % 100 % 10 - 1]);
}
}
} else {
if (x < 20) {
printf("%s", a[x - 1]);
} else {
printf("%s-%s", b[x / 10 - 2], a[x % 10 - 1]);
}
}
}
return 0;
}