看来作为码农得天天写代码啊[hdu1228]

直接上代码:

 
  
1 #include < stdio.h >
2 #include < string .h >
3 #include < stdlib.h >
4
5
6   const char * numbers[] = { " zero " , " one " , " two " , " three " , " four " , " five " , " six " ,\
7 " seven " , " eight " , " nine " ,NULL};
8
9   int read_word( char * num, char ** at)
10 {
11 char * start;
12 if ( !** at)
13 return 0 ;
14
15 start = * at;
16 while ( ** at != ' ' && ** at != ' \0 ' )
17 {
18 ( * at) ++ ;
19 }
20 ** at = ' \0 ' ;
21 ( * at) ++ ;
22 if ( * start < ' a ' || * start > ' z ' )
23 {
24 return 0 ;
25 }
26 strcpy(num,start);
27 // now skip to the nonspace
28   while ( ** at == ' ' && ** at != ' \0 ' )
29 ( * at) ++ ;
30 return 1 ;
31 }
32
33 int word2num( const char * num)
34 {
35 int rt = 0 ;
36 const char ** i = numbers;
37 while ( * i)
38 {
39 if ( ! strcmp( * i,num))
40 return rt;
41 rt ++ ;
42 i ++ ;
43 }
44 return rt;
45 }
46
47
48 int main()
49 {
50 char * line;
51 char * num;
52 int done = 0 ;
53 line = ( char * )malloc( 50 * sizeof ( char ));
54 num = ( char * )malloc( 10 * sizeof ( char ));
55
56
57 while ( ! done)
58 {
59 int add11,add12,add21,add22;
60 char * at;
61 int rt;
62 fgets(line, 50 ,stdin);
63
64 add11 = add12 = add21 = add22 = 0 ;
65 at = line;
66
67 // oprand 1
68 rt = read_word(num, & at);
69 if ( ! rt)
70 {
71 printf( " input error!\n " );
72 return 0 ;
73 }
74 add11 = word2num(num);
75 // read the second num and skip the + or skip the +
76 if (read_word(num, & at))
77 {
78 add12 = word2num(num);
79 add11 = add11 * 10 ;
80 read_word(num, & at); // skip the +
81 }
82 // anther oprand
83 read_word(num, & at);
84 add21 = word2num(num);
85 if (read_word(num, & at))
86 {
87 add21 = add21 * 10 ;
88 add22 = word2num(num);
89 }
90 if (add11 == 0 && add12 == 0 && add21 == 0 && add22 == 0 )
91 {
92 done = 1 ;
93 break ;
94 }
95 printf( " %d\n " ,add11 + add12 + add21 + add22);
96 }
97 free(num);
98 free(line);
99 return 0 ;
100 }
101
102
103
104

顺便说一下,hdu的gcc编译器什么版本,连//风格的注释都不支持...囧!

转载于:https://www.cnblogs.com/wwillforever/archive/2011/03/07/1976313.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值