hdu 1228

    xiaoxiao2024-07-23  10

    题目概述

    给定两个小于100的正整数A和B,计算A+B 需要注意的是:A和B的每一位数字由对应的英文单词给出

    时限

    1000ms/2000ms

    输入

    每行若干个字符串,均为题目所述格式,输入到EOF结束

    限制

    没有限制

    输出

    每行一个数,为结果

    样例输入

    one + two = three four + five six = zero seven + eight nine = zero + zero =

    样例输出

    3 90 96

    讨论

    水题,读入字符串,处理,A+B,输出 水题最烦人的地方就是题目概述不好写,输入输出也没有固定格式 中文题还好点……

    题解状态

    0MS,1712K,1044 B,C++

    题解代码

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define INF 0x3f3f3f3f #define MAXN 302 #define memset0(a) memset(a,0,sizeof(a)) char str[10];//读入的每个数的字符串 int fun()//仅仅被用来处理一下输入 { if (str[0] == 'z') return 0; else if (str[0] == 'o') return 1; else if (str[0] == 't'&&str[1] == 'w') return 2; else if (str[0] == 't'&&str[1] == 'h') return 3; else if (str[0] == 'f'&&str[1] == 'o') return 4; else if (str[0] == 'f'&&str[1] == 'i') return 5; else if (str[0] == 's'&&str[1] == 'i') return 6; else if (str[0] == 's'&&str[1] == 'e') return 7; else if (str[0] == 'e') return 8; else return 9; } int main(void) { //freopen("vs_cin.txt", "r", stdin); //freopen("vs_cout.txt", "w", stdout); while (1) { int num1 = 0, num2 = 0, num; while (scanf("%s", str) && str[0] != '+') //input num1 = num1 * 10 + fun(); while (scanf("%s", str) && str[0] != '=') //input num2 = num2 * 10 + fun(); if (num1 == 0 && num2 == 0) return 0; else printf("%d\n", num1 + num2);//output } }

    EOF

    转载请注明原文地址: https://ju.6miu.com/read-1290963.html
    最新回复(0)