T1 汉字大写金额

T1 汉字大写金额,第1张

T1 汉字大写金额

输出大写金额。

输入格式

数字金额(正实数)

输出格式

大写金额

大写数字和金额单位所使用的汉字分别为:

  • 数字 0 ~ 9 的大写依次为:零、壹、贰、叁、肆、伍、陆、柒、捌、玖。
  • 金额单位由小大到依次为:分、角、元、拾、佰、仟、万、拾、佰、仟、亿。
  • 输入样例1

    0.0032

    结尾无空行

    输出样例1

    零分

    结尾无空行

    输入样例2

    500016.038

    结尾无空行

    输出样例2

    伍拾零万零仟零佰壹拾陆元零角肆分

    结尾无空行

    #include 
    void CurPrint(double amount);
    
    int main()
    {
        double amount;
        scanf_s("%lg", &amount);
        CurPrint(amount);
        putchar('n');
        return 0;
    }
    void CurPrint(double amount)
    {
        long long am;
        int i,start;
        am = (long long)((amount+0.005) * 100);
        int a[11];
        for(i=10;i>=0;i--)
        {
            a[i] = am%10 ;
            am = am / 10;
        }
        for (i = 0; i < 11; i++)
        {
            if (a[i] != 0)
            {
                start = i;
                break;
            }
        }
        if (i == 11)
        {
            printf("零分");
        }
        else
        {
            for (i=start; i < 11; i++)
            {
                if (a[i] == 1)printf("壹");
                else if (a[i] == 2)printf("贰");
                else if (a[i] == 3)printf("叁");
                else if (a[i] == 4)printf("肆");
                else if (a[i] == 5)printf("伍");
                else if (a[i] == 6)printf("陆");
                else if (a[i] == 7)printf("柒");
                else if (a[i] == 8)printf("捌");
                else if (a[i] == 9)printf("玖");
                else if (a[i] == 0)printf("零");
    
                if (i == 3 || i == 7 )printf("拾");
                else if (i == 2 || i == 6 )printf("佰");
                else if (i == 1 || i == 5 )printf("仟");
                else if (i == 4)printf("万");
                else if (i == 0)printf("亿");
                else if (i == 8)printf("元");
                else if (i == 9)printf("角");
                else if (i == 10)printf("分");
            }
        }
    }

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5520638.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存