字符指針變量數組的用法
我們知道,char *s="aisdfj"; 是成立的。
于是char *s[]={"one", "two", ……}也是成立的。
就相當于把char *s看成另外一種類型的變量一樣。
其實,就這么簡單。
Sample Input
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
Sample Output
3
90
96
View Code
#include "stdio.h"
#include "string.h"
char *map[]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
char s[10];
int k=0, num[2]={0};
while(scanf("%s", s)==1)
{
if(strcmp(s, "+")==0) k++;
else if(strcmp(s, "=")==0)
{
if(num[0]==0 && num[1]==0) break;
else
{
printf("%d\n", num[0]+num[1]);
k = 0; num[0]=0, num[1]=0;
}
}
else
{
for(int i=0; i<10; i++)
if(strcmp(s, map[i])==0) num[k] = num[k]*10+i;
}
}
return 0;
}
posted on 2011-12-01 16:14 More study needed. 閱讀(244) 評論(0) 收藏 舉報

浙公網安備 33010602011771號