作业二(改二)

编程总结2
题目2:币值转换
我的代码:

include <stdio.h>
include <string.h>
void printNumber(char s, int i, int len);
void printPlace(char s, int, int);

int main()
{
char s[11];
int i, strLen;

gets(s);
strLen = (int)strlen(s);

if (strLen == 1 && s[0] == '0') {
printf("a\n");
return 0;
}

for (i=0; i<strLen; i++) {
if (s[i] == '0') {
if (strLen-i == 5) {
if (s[1]!='0' || s[2]!='0' || s[3]!='0' || s[4]!='0' || strLen < 9) {
printf("W");
}
}
if (s[i+1] != '0' && s[i+1] != '\0' && (strLen-i != 5)) {
printf("a");
}
continue;
}else {
printNumber(s, i, strLen);
if (strLen-i == 5) {
if (s[1]!='0' || s[2]!='0' || s[3]!='0' || s[4]!='0' || strLen < 9) {
printf("W");
}
}
}

if (strLen-i == 9) {
    printf("Y");
}

}

return 0;
}

void printNumber(char *s, int i, int len)
{
int num = s[i] - '0';

switch (num) {
case 0:
printf("a");
if (s[i] != '0') {
printPlace(s, len-i, len);
}
break;
case 1: printf("b"); printPlace(s, len-i, len); break;
case 2: printf("c"); printPlace(s, len-i, len); break;
case 3: printf("d"); printPlace(s, len-i, len); break;
case 4: printf("e"); printPlace(s, len-i, len); break;
case 5: printf("f"); printPlace(s, len-i, len); break;
case 6: printf("g"); printPlace(s, len-i, len); break;
case 7: printf("h"); printPlace(s, len-i, len); break;
case 8: printf("i"); printPlace(s, len-i, len); break;
case 9: printf("j"); printPlace(s, len-i, len); break;
}
}

void printPlace(char *s, int i, int len)
{
switch (i) {
case 1: break;
case 2: printf("S"); break;
case 3: printf("B"); break;
case 4: printf("Q"); break;
case 5: break;
case 6: printf("S"); break;
case 7: printf("B"); break;
case 8: printf("Q"); break;
}
}

2.解题流程图

3.题目中遇到的难题与解决办法
4.运行结果截图

posted @ 2019-02-18 10:12  404NFD  阅读(147)  评论(0编辑  收藏  举报