PAT a1005题解

来源:互联网 发布:无人机地面站软件 编辑:程序博客网 时间:2024/06/05 08:37
#include <cstdio>#include <cstring>char* change(int n){switch(n){case 0: return "zero"; break;case 1: return "one"; break;case 2: return "two"; break;case 3: return "three"; break;case 4: return "four"; break;case 5: return "five"; break;case 6: return "six"; break;case 7: return "seven"; break;case 8: return "eight"; break;case 9: return "nine"; break;}}int main(){int sum = 0;char a[105];scanf("%s", a);int len = strlen(a);for(int i = 0; i < len; i++){sum = sum + a[i] - '0';}int bai, shi, ge;bai = sum / 100;shi = sum / 10 % 10;ge = sum % 10;if(bai != 0){printf("%s %s %s", change(bai), change(shi), change(ge));}else{if(shi != 0){printf("%s %s", change(shi), change(ge));}else{printf("%s", change(ge));}}return 0;}

原创粉丝点击