Renminbi conversion: Numbers to Chinese uppercase

Exam questions and main points:

  1. The Chinese capitalized amount should be marked with "RMB" before the figure. Chinese capital figures should be filled in with words such as one, two, three, four, five, lu, seven, ba, nine, ten, hundred, thousand, one million, one hundred million, yuan, angle, minute, zero, whole, etc. (30 points)
  2. If the Chinese capitalized amount number ends at "yuan", after "yuan", write "whole word, such as ¥532.00, it should be written as "RMB five hundred and three and two yuan". Do not write after "jiao" and "divide" Whole word. (30 points)
  3. When there is a "0" in the middle of the Arabic numerals, write "zero" in Chinese capitals, and when there are several consecutive "0"s in the middle of the Arabic numerals, only write a "zero" in the middle of the Chinese capital amount, such as RMB6007.14, it should be written as "RMB" "Lu Qianlingqiyuan and one jiao are divided." (40 marks)

Enter description:

输入一个double数

Output description:

输出人民币格式

Example 1

enter

151121.15

Output

人民币壹拾伍万壹仟壹佰贰拾壹元壹角伍分
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char number[]="零壹贰叁肆伍陆柒捌玖拾佰仟万亿整分角元";
    int seq[200];
    char str[200];
    char spp[200];
    double num;
    int intNum;
    int dbNum;
    while(scanf("%lf",&num)!=EOF)
    {
        intNum=(int)num;
        num-=intNum;
        num*=100;
        dbNum=(int)(num+0.5);
        int len=0;
        while(intNum>0)
        {
            str[len++]=intNum%10+'0';
            intNum/=10;
        }
        str[len]='\0';
        int p=0;
        int flag=1;
        for(int i=len-1; i>=0; i--)
        {
            if(i%4==3)flag=1;
            if(str[i]=='0')
            {
                flag=0;
                if(i==8)seq[p++]=14;
                if(i==4)seq[p++]=13;
                if(i==0)seq[p++]=18;
                continue;
            }
            if(str[i]!='0'&&flag==0)
            {
                seq[p++]=0;
                flag=1;
            }
            seq[p++]=str[i]-'0';
            if(i%4>0)seq[p++]=i%4+9;
            if(i==8)seq[p++]=14;
            if(i==4)seq[p++]=13;
            if(i==0)seq[p++]=18;
        }
        if(dbNum==0)
            seq[p++]=15;
        else if(dbNum<10)
        {
            seq[p++]=dbNum;
            seq[p++]=16;
        }
        else if(dbNum==10)
        {
            seq[p++]=dbNum/10;
            seq[p++]=17;
        }
        else
        {
            seq[p++]=dbNum/10;
            seq[p++]=17;
            seq[p++]=dbNum%10;
            seq[p++]=16;
        }
        int l=0;
        for(int i=0; i<p; i++)
        {
            spp[l++]=number[seq[i]*2];
            spp[l++]=number[seq[i]*2+1];
        }
        spp[l]='\0';
        printf("人民币%s\n",spp);
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_43307431/article/details/107483127