# 编程题(请使用C语言或者C++完成以下题目):

## 添加输出负数操作：

 if(sum<0)
{
printf("负");
sum=0-sum;
}


## 字符简化转变：

int changeA(int num)
{
if (num == -63)return 0;
if (num == -46)return 1;
if (num == -74)return 2;
if (num == -56)return 3;
if (num == -53)return 4;
if (num == -50)return 5;
if (num == -63)return 6;
if (num == -58)return 7;
if (num == -80)return 8;
if (num == -66)return 9;
if (num == -54)return 10;
}


## 简单的测试：

#### 样例一

整数 钱包 等于 零



#### 样例二

整数 钱包 等于 六



## 代码主体：

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int changeA(int num)
{
if (num == -63)return 0;
if (num == -46)return 1;
if (num == -74)return 2;
if (num == -56)return 3;
if (num == -53)return 4;
if (num == -50)return 5;
if (num == -63)return 6;
if (num == -58)return 7;
if (num == -80)return 8;
if (num == -66)return 9;
if (num == -54)return 10;
}
void changeB(int number)
{
if (number == 0)printf("零");
else if (number == 1)printf("一");
else if (number == 2)printf("二");
else if (number == 3)printf("三");
else if (number == 4)printf("四");
else if (number == 5)printf("五");
else if (number == 6)printf("六");
else if (number == 7)printf("七");
else if (number == 8)printf("八");
else if (number == 9)printf("九");
else if (number == 10)printf("十");
}
int main()
{
int caozuo(char caozuo[20]);
int changeA(int num);
void changeB(int number);
int sum, putness, ones, twos, countness, bianL;
char a[20], b[20], c[20], d[20];
scanf("%s %s %s %s", a, b, c, d);
countness = strlen(d);
if (countness == 4)
{
bianL = d[0];
if (bianL != -54)sum = changeA(bianL) * 10;
if (bianL == -54)sum = 10 + changeA(d[2]);
}
if (countness == 6)
{
bianL = d[0];
sum = changeA(bianL) * 10;
bianL = d[4];
sum += changeA(bianL);
}
if (countness == 2)sum = changeA(d[0]);
while (1)
{
scanf("%s ", a);
if (strcmp(a, "看看") == 0)break;
scanf("%s %s", b, c);
putness = caozuo(b);
if (putness)sum += changeA(c[0]);
else sum -= changeA(c[0]);
}
if(sum<0)
{
printf("负");
sum=0-sum;
}
if (sum <= 10&&sum>0)changeB(sum);
if (sum >= 20)
{
twos = sum % 10;
ones = (sum / 10) % 10;
changeB(ones);
printf("十");
changeB(twos);
}
if (sum > 10 && sum < 20)
{
printf("十");
twos = sum % 10;
changeB(twos);
}
system("pause");
}
int caozuo(char caozuo[20])
{
if (strcmp(caozuo, "减少") == 0)return 0;
else return 1;
}

posted @ 2020-02-16 17:32  南海蛟龙  阅读(99)  评论(0编辑  收藏  举报