pta寒假作业2

题目二币值转换

题目代码

    #include<stdio.h>

int main (void)

{

int n, initial_n;

scanf("%d", &n);

initial_n = n; 

char num[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};

char unit[10] = {0, 0, 'S', 'B', 'Q', 'W', 'S', 'B', 'Q', 'Y'};

char result[17]={0}; 

int i, last_i = n % 10; 

int j = 0;

int count_n = 0;

while (n > 0) {

 i = n % 10;

n /= 10;

count_n ++;

if (i == 0 && (count_n % 4) > 1) { 

 if (last_i != 0) {   
result[j++] = num[i];    

 } 

if (count_n == 5 && i == 0 && initial_n < 100000000) {

result[j++] = unit[count_n];    

}

 if (count_n > 1 && i != 0) {    

 result[j++] = unit[count_n];

if (i != 0) {               

result[j++] = num[i];

}

for (j=j-1; j>=0; j--) {
printf("%c", result[j]);
}
printf(" ");

return 0;
}

设计思路:开始→用charnum和charunit分别表示数字和单位→输入n,initial→判断n,当n的条件满足什么样执行题目要求对count-n做出相应的处理→再运用一系列判断条件改变resultt[j++]→最后按要求输出结果

遇到的问题:这题目大问题编译总是错误

 

解决方法:问同学感觉他们也不是很清晰,然后看了大佬博客稍稍懂了那么一点点

原文地址:https://www.cnblogs.com/1793979463hyx/p/10410963.html