列表

详情


HJ95. 人民币转换

描述

考试题目和要点:

1、中文大写金额数字前应标明“人民币”字样。中文大写金额数字应用壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、零、整等字样填写。

2、中文大写金额数字到“元”为止的,在“元”之后,应写“整字,如532.00应写成“人民币伍佰叁拾贰元整”。在”角“和”分“后面不写”整字。

3、阿拉伯数字中间有“0”时,中文大写要写“零”字,阿拉伯数字中间连续有几个“0”时,中文大写金额中间只写一个“零”字,如6007.14,应写成“人民币陆仟零柒元壹角肆分“。
4、10应写作“拾”,100应写作“壹佰”。例如,1010.00应写作“人民币壹仟零拾元整”,110.00应写作“人民币壹佰拾元整”
5、十万以上的数字接千不用加“零”,例如,30105000.00应写作“人民币叁仟零拾万伍仟元整”


输入描述

输入一个double数

输出描述

输出人民币格式

示例1

输入:

151121.15

输出:

人民币拾伍万壹仟壹佰贰拾壹元壹角伍分

示例2

输入:

1010.00

输出:

人民币壹仟零拾元整

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C 解法, 执行用时: 1ms, 内存消耗: 268KB, 提交时间: 2021-02-06

#include <stdio.h>
#include <string.h>
char Big_Ch_Num[][4] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };
char section_unit[][4] = {
  "", "拾", "佰", "仟", 
"万", "拾", "佰", "仟", 
"亿", "拾", "佰", "仟", 
"兆", "拾", "佰", "仟", 
"京", "拾", "佰", "仟", 
"垓", "拾", "佰", "仟", 
"秭", "拾", "佰", "仟", 
"穰", "拾", "佰", "仟", 
"沟", "拾", "佰", "仟", 
"涧", "拾", "佰", "仟", 
"正", "拾", "佰", "仟", 
"载", "拾", "佰", "仟"
};
int main(void)
{
	char i, j, k, ch, s[128], len, zero_cnt, jiao, fen;
	for( ; scanf("%s", s)!=EOF; ){
		printf("人民币");
		len = strlen(s);
		for(i=len-1; i>=0; i--)
			if(s[i] == '.') break;
		jiao = fen = 0;
		if(i == -1) j=len-1;
		else{
			j=i-1;   i++;
			if(i < len){
				jiao = s[i++]-48;
				if(i < len) fen = s[i]-48;
			}
		}
		i=zero_cnt=0;   k=j;
		for( ; k>=0; i++,k--){
			if((ch=s[i]) != '0'){
				if(zero_cnt){ printf("零");   zero_cnt=0; }
				if(ch!='1' || k%4!=1) printf("%s", Big_Ch_Num[ ch-48 ]);
				printf("%s", section_unit[ k ]);
				continue;
			}
			zero_cnt++;
			if(k%4) continue;
			if(zero_cnt != 4) printf("%s", section_unit[ k ]);
			zero_cnt = 0;
		}
		if(j || s[j]!='0') printf("元");
		else{
			if(jiao+fen) goto rpt;
			printf("零元整\n");   continue;
		}
		if(jiao+fen){
rpt:		if(jiao) printf("%s角", Big_Ch_Num[ jiao ]);
			fen ? printf("%s分\n", Big_Ch_Num[ fen ]) : printf("\n");
		}
		else printf("整\n");
	}
	return 0;
}

C 解法, 执行用时: 1ms, 内存消耗: 368KB, 提交时间: 2021-03-02

#include"stdio.h"

int pre=1;
void OutPutNum(int num, int type){
    if(type){
        if(num>100000000) num/=10000;
        if(num<100000000 && num>10000) num/=10000;
        switch (num){
            case 1 :  printf("元"); break;
            case 10 :  printf("拾"); break;
            case 100 :  printf("佰"); break;
            case 1000 :  printf("仟"); break;
            case 10000 :  printf("万"); break;
            case 100000000 :  printf("亿"); break;
            default: break;
        }
        return;
    }
    switch (num){
        case 0 :  if(pre){printf("零");  pre = 0; }
            break;
        case 1 :  printf("壹"); pre = 1;break;
        case 2 :  printf("贰"); pre = 1;break;
        case 3 :  printf("叁"); pre = 1;break;
        case 4 :  printf("肆"); pre = 1;break;
        case 5 :  printf("伍"); pre = 1;break;
        case 6 :  printf("陆"); pre = 1;break;
        case 7 :  printf("柒"); pre = 1;break;
        case 8 :  printf("捌"); pre = 1;break;
        case 9 :  printf("玖"); pre = 1;break;
        default: break;
    }
}
int main(void){
    double n;
    while(scanf("%lf", &n) != EOF){
        int i,level=1,l=0,value,num,xo;
        num = (int)n;
        xo = (1000*n - 1000*num)/10;
        while(num-level >= 0)  level*=10;
        printf("人民币");
        for(level/=10; level>=1; level/=10){
            value = (int)num/level;
            num = num%level;
            if(value==0 && level==10000){}
            else if(value==1 && (level==10|| level==100000)){}
            else
                OutPutNum(value,0);
            if(value || (level==10000) || (level==100000000)) OutPutNum(level,1);
            if(0==num && level>1){printf("元");break;}
        }
        if(xo<1) printf("整");
        else{
            value = xo/10;
            if(value){
                OutPutNum(value,0);
                printf("角");
            }
            value = xo%10;
            if(value){
                OutPutNum(value,0);
                printf("分");
            }
        }
        printf("\n");
    }
}

上一题