题解 | #学英语#

学英语

http://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc

#include <stdio.h>
#include <string.h>



void transform_three_num(int n);
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
int a,b,c;
c = n%1000;
b = (n/1000)%1000;
a = n/1000000;

if(a){
  transform_three_num(a);
  printf(" million");
}

if(a!=0 && b!=0 )
printf(" ");
if(b){

  transform_three_num(b);
  printf(" thousand");
}

if(b!=0 && c!=0 ||  a!=0 && c!=0 )
printf(" ");
if(c){
  transform_three_num(c);
}

printf("\n");

}






  return 0;
}


void transform_three_num(int n){
int single,ten,hundred;
hundred = n/100;
ten = (n/10)%10;
single = n%10;
switch (hundred)
{
case 1:
  printf("one hundred");
  break;
case 2:
  printf("two hundred");
  break;
  case 3:
  printf("three hundred");
  break;
  case 4:
  printf("four hundred");
  break;
  case 5:
  printf("five hundred");
  break;
  case 6:
  printf("six hundred");
  break;
  case 7:
  printf("seven hundred");
  break;
  case 8:
  printf("eight hundred");
  break;
  case 9:
  printf("nine hundred");
  break;
default:
  break;
}
if(hundred!=0 && ten+single!=0){
  printf(" and ");
}

if(ten ==1){
  switch(n%100){
    case 10:
    printf("ten");
    break;
        case 11:
    printf("eleven");
    break;
        case 12:
    printf("tweleve");
    break;
        case 13:
    printf("thirteen");
    break;
        case 14:
    printf("fourteen");
    break;
        case 15:
    printf("fifteen");
    break;
        case 16:
    printf("sixteen");
    break;
        case 17:
    printf("seventee");
    break;
        case 18:
    printf("eighteen");
    break;
        case 19:
    printf("nineteen");
    break;
  }
}
else{
  switch (ten)
  {
  case 2:
  printf("twenty");
  break;
  case 3:
  printf("thirty");
  break;
  case 4:
  printf("forty");
  break;
  case 5:
  printf("fifty");
  break;
  case 6:
  printf("sixty");
  break;
  case 7:
  printf("seventy");
  break;
  case 8:
  printf("eighty");
  break;
  case 9:
  printf("ninety");
  break;
default:
  break;
  }


if(ten!=0 && single!=0)
printf(" ");
 switch (single)
  {
    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;
default:
  break;
  }

}


}




全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
3 2 评论
分享
牛客网
牛客企业服务