书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

字符指针变量数组的用法

我们知道,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.  阅读(237)  评论(0编辑  收藏  举报

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!