题解 | #学英语#

学英语

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

英语成为了最大的BUG 改了好多次单词拼写。。。
#include <stdio.h>
#include <stdlib.h>
    char biao1[][20]={"","one","two","three","four","five","six","seven","eight","nine",\
        "ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",\
        "eighteen","nineteen"};
    char biao2[][20]={"","","twenty","thirty","forty","fifty","sixty","seventy","eighty",\
        "ninety"};
    char biao3[][20]={"billion","million","thousand","hundred","and"};
void shuchu(int outcnt,char** output)
{
    for(int i=0;i<outcnt;i++)
        printf("%s ",output[i]);
}
void small1000(int weishu,char* place)
{   
    int outcnt=0;
    char * output[10];
    if(weishu==3)
    {
        output[outcnt++]=biao1[place[weishu-1]];
        output[outcnt++]=biao3[3];
        shuchu(outcnt,output);
    if(place[1] || place[0])
        printf("and ");
        else
        {   
            //shuchu(outcnt,output);
            return;
        }
        outcnt=0;
      if (place[1]>1)
      {
          output[outcnt++]=biao2[place[1]];
          if (place[0])
          {
              output[outcnt++]=biao1[place[0]];
          }
      }
        else
        {
            output[outcnt++]=biao1[place[1]*10+place[0]];
        }
        shuchu(outcnt,output);
        return ;
    }
    else if(weishu==2)
    {
        if (place[1]>1)
      {
          output[outcnt++]=biao2[place[1]];
          if (place[0])
          {
              output[outcnt++]=biao1[place[0]];
          }
      }
        else
        {
            output[outcnt++]=biao1[place[1]*10+place[0]];
        }
        shuchu(outcnt,output);
        return ;
    }
    else
    {
      printf("%s ",biao1[place[0]]);
    }
}
int main()
{
    long int x=0;
    scanf("%d",&x);
    int temp=0;
    int dc=0;
    char* output[50]={0};
    char place[10]={0};
    int weishu=0;
    int outcnt=0;
   while(x)
   {
       place[weishu++]=x%10;
       x=x/10;           
   }
    if(weishu==7)
    {
        output[outcnt++]=biao1[place[weishu-1]];
        output[outcnt++]=biao3[1];
        for (int i=5;i>=0;i--)
        {
            if (place[i])
            {
                weishu=i+1;
                break;
            }
            
        }
        if (weishu==7)
        {
            //后面全是0
            shuchu(outcnt,output);
            return 0;
        }
       shuchu(outcnt,output);
    outcnt=0;
    }

    if(weishu>3 && weishu<7)
    {
        small1000(weishu-3, place+3);
        printf("thousand ");
        temp=weishu;
        for (int i=2;i>=0;i--)
        {
            if (place[i])
            {
                weishu=i+1;
  //              printf("and ");
            break;
            }
        }
        if (temp==weishu)
        {
           
            return 0;
        }
    }
    small1000(weishu,place);
    
    
}


全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务