本文主要是介绍HDU 1228 A + B 字符串水题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
HDU 1228 A + B 字符串水题
总之就是很水。。。。
#include <stdio.h>
#include <string.h>char num[55][55];
int sum;
int len[2];
int n;
int a;
int t;
int shu[2][55];
int main()
{while (1){a = 0;t = 0;sum = 0;memset(shu, 0, sizeof(shu));memset(len, 0, sizeof(len));memset(num, 0, sizeof(num));while (scanf("%s", num[t]) != EOF && strcmp(num[t], "=") != 0){if (strcmp (num[t], "+") == 0){a ++;}else{if (strcmp (num[t], "zero") == 0){shu[a][len[a]] = 0; }if (strcmp (num[t], "one") == 0){shu[a][len[a]] = 1; }if (strcmp (num[t], "two") == 0){shu[a][len[a]] = 2; }if (strcmp (num[t], "three") == 0){shu[a][len[a]] = 3; }if (strcmp (num[t], "four") == 0){shu[a][len[a]] = 4; }if (strcmp (num[t], "five") == 0){shu[a][len[a]] = 5; }if (strcmp (num[t], "six") == 0){shu[a][len[a]] = 6; }if (strcmp (num[t], "seven") == 0){shu[a][len[a]] = 7; }if (strcmp (num[t], "eight") == 0){shu[a][len[a]] = 8; }if (strcmp (num[t], "nine") == 0){shu[a][len[a]] = 9; } len[a] ++;}}n = 0;for (int i = 0; i < len[0]; i ++){n = n * 10 + shu[0][i];}sum += n;n = 0;for (int i = 0; i < len[1]; i ++){n = n * 10 + shu[1][i];}sum += n;if (sum == 0)break;elseprintf("%d\n", sum);}return 0;
}
这篇关于HDU 1228 A + B 字符串水题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!