首页 > 其他 > 详细

题目2.7-1 币值转换

时间:2019-02-20 22:04:15      阅读:220      评论:0      收藏:0      [点我收藏+]

题目2.7-1 币值转换(20 分)

7-1 币值转换 (20 分)

输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式。如23108元,转换后变成“贰万叁仟壹百零捌”元。为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S、B、Q、W、Y分别代表拾、百、仟、万、亿。于是23108元应被转换输出为“cWdQbBai”元。

输入格式:

输入在一行中给出一个不超过9位的非负整数。

输出格式:

在一行中输出转换后的结果。注意“零”的用法必须符合中文习惯。

输入样例1:

813227345

输出样例1:

iYbQdBcScWhQdBeSf

输入样例2:

6900

输出样例2:

gQjB

1.实验代码

#include<stdio.h>
char shu(int x);
char wei(int count);
int main()
{   
int count,number,n,i,j,k,x,y,d;
int a[9];
char b[16]; 
i=0;
scanf("%d",&number);
if(number==0){
    printf("a");
}
else
do{ n=number%10;
    number=number/10; 
    a[i]=n;
    i++;
}while(number!=0&&i<=9);
k=i;
i=0;
d=0;
count=1;
for(j=0;j<k;j++){
    x=a[i];
    if(count==1&&x!=0){
    b[d++]=shu(x);
}
    if(count!=1&&count!=5&&count!=9&&x!=0){
    b[d++]=wei(count);
    b[d++]=shu(x);
}
    if (x==0&&(count%4)>1){ 
    if (y != 0) {
    b[d++]  = shu(x);    
    }
}
    if(count==5){
    if(x==0){
    b[d++]=wei(count);
    }
    else
    {
    b[d++]=wei(count);
    b[d++]=shu(x);
    }
    }
    if(count==9){
    if(x!=0);
    b[d++]=wei(count);
    b[d++]=shu(x);
}

    y=x;
    i++;
    count++;
}
d=d-1;
for(d;d>=0;d--){
    printf("%c",b[d]);
}
return 0;
}

char shu(int x)
{
    if(x==0)
    return ‘a‘;
    if(x==1)
    return ‘b‘;
    if(x==2)
    return ‘c‘;
    if(x==3)
    return ‘d‘;
    if(x==4)
    return ‘e‘;
    if(x==5)
    return ‘f‘;
    if(x==6)
    return ‘g‘;
    if(x==7)
    return ‘h‘;
    if(x==8)
    return ‘i‘;
    if(x==9)
    return ‘j‘;
}

char wei(int count)
{
    if(count==9)
    return ‘Y‘;
    if(count==8)
    return ‘Q‘;
    if(count==7)
    return ‘B‘;
    if(count==6)
    return ‘S‘;
    if(count==5)
    return ‘W‘;
    if(count==4)
    return ‘Q‘;
    if(count==3)
    return ‘B‘;
    if(count==2)
    return ‘S‘;
    else
    return 0;
}

2.设计思路

st=>start: 声明函数,定义变量
op1=>operation: 利用while和if语句来进行特殊类型的筛选
sub1=>subroutine: 利用自定义函数来实现依次输出
op2=>operation: 在利用for语句来进行判断
e=>end: 结束程序

st->op1->op2->sub1->e

3.本题调试过程碰到问题及解决办法

错误截图:

多次思考得出正确结果,并未保存错误截图

解决办法:

网上查询,询问同学!

4.运行结果截图

技术分享图片

题目2.7-1 币值转换

原文:https://www.cnblogs.com/LfanWyuXooo/p/10409533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!