2011-12-20 11:29:53
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1228
题意:中文。
代码:
# include <stdio.h>
# include <string.h>
int a, b, cnt ;
char str[110] ;
char words[11][11] ;
void getword()
{
int i, cc = 0 ;
char cur_word[11] ;
cnt = 0 ;
for (i = 0 ; str[i] ; i++)
{
if (str[i] == ' ')
{
cur_word[cc++] = '\0' ;
strcpy (words[cnt++], cur_word) ;
cc = 0 ;
}
else
cur_word[cc++] = str[i] ;
}
}
int translate(char s[])
{
//zero one two three four five six seven eight nine
if (s[0] == 'z') return 0 ;
if (s[0] == 'o') return 1 ;
if (s[0] == 'e') return 8 ;
if (s[0] == 'n') return 9 ;
if (s[0] == 't') return (s[1] == 'w')? 2 : 3 ;
if (s[0] == 'f') return (s[1] == 'o')? 4 : 5 ;
if (s[0] == 's') return (s[1] == 'i')? 6 : 7 ;
return -1 ;
}
void getnum()
{
int i = 0 ;
a = b = 0 ;
while (i < cnt)
{
if (words[i][0] == '+') break ;
a = a * 10 + translate(words[i]) ;
i++ ;
}
i++ ;
while (i < cnt)
b = b * 10 + translate(words[i++]) ;
}
int main ()
{
while (gets(str))
{
getword() ;
getnum() ;
if (a == 0 && b==0) break ;
printf ("%d\n", a+b ) ;
}
return 0 ;
}