匿名用户
1级
2010-05-09 回答
最后输出是用的是阿拉伯数字,这个你再改改吧, 小问题了。。。。
#include
#include
#include
#include
#include
int carry = 0;
int parse_int(const char *s, int len)
{
char tens[10], units[10];
memset(tens, 0, sizeof(tens));
memset(units, 0, sizeof(units));
int i=0, count=0;
while (isalpha(s[i]))
tens[count++] = s[i++];
while (isspace(s[i]))
i++;
count = 0;
if (i == len) {
switch (s[count++]) {
case 'z':
return 0;
case 'o':
return 1;
case 't':
switch (s[count]) {
case 'w':
return 2;
case 'h':
return 3;
case 'e':
return 10;
}
case 'f':
switch (s[count]) {
case 'o':
return 4;
case 'i':
return 5;
}
case 's':
switch (s[count]) {
case 'i':
return 6;
case 'e':
return 7;
}
case 'e':
return 8;
case 'n':
return 9;
}
count = 0;
}
else {
while (isalpha(s[i]))
units[count++] = s[i++];
count = 0;
if (!strcmp(units, "zero"))
i = 0;
else if (!strcmp(units, "one"))
i = 1;
else if (!strcmp(units, "two"))
i = 2;
else if (!strcmp(units, "three"))
i = 3;
else if (!strcmp(units, "four"))
i = 4;
else if (!strcmp(units, "five"))
i = 5;
else if (!strcmp(units, "six"))
i = 6;
else if (!strcmp(units, "seven"))
i = 7;
else if (!strcmp(units, "eight"))
i = 8;
else if (!strcmp(units, "nine"))
i = 9;
switch (tens[count++]) {
case 'z':
return i;
case 'o':
return 10+i;
case 't':
switch (s[count]) {
case 'w':
return 20 + i;
case 'h':
return 30 + i;
}
case 'f':
switch (s[count]) {
case 'o':
return 40 + i;
case 'i':
return 50 + i;
}
case 's':
switch (s[count]) {
case 'i':
return 60 + i;
case 'e':
return 70 + i;
}
case 'e':
return 80 + i;
case 'n':
return 90 + i;
}
}
}
int main()
{
char A[20], B[20], line[100];
int i, count, a, b;
while (1) {
i = count = a = b = 0;
memset(A, 0, sizeof(A));
memset(B, 0, sizeof(B));
if (fgets(line, sizeof(line), stdin) == NULL)
break;
while (!isalpha(line[i]))
i++;
while (line[i] != '+')
A[count++] = line[i++];
count = 0;
i++;
while (!isalpha(line[i]))
i++;
while (line[i] != '=')
B[count++] = line[i++];
a = parse_int(A, strlen(A));
b = parse_int(B, strlen(B));
printf("%d\n", a+b);
}
return 0;
}