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;
else
printf("%d\n", sum);
}
return 0;
}