1001 DotNotation

1001 DotNotation

This is an easy problem. It's just aim to practice  string manipulation, The most important thing is that you should remember that the chars in the string of  given input is not only "0123456789"、"+ - * /"、"." ,there  are also some other chars that you may haven't realized. So, besides judging the a[ i ] whether a digt or a operater,  you may need add such a select case

" if ( a[ i ] != '.' )   ……" .

Ok, next come the AC code! you can refer to it but not depends heavily on it ! 

View Code
1 #include<stdio.h>
2 #include<string.h>
3  int main()
4 { int b,t,i;
5 char a[51],ch;
6 scanf("%d",&t);
7 scanf("%c",&ch);
8 while(t--)
9 { int p=0;
10 gets(a);
11 b=strlen(a);
12 if(a[0]<'0'||a[0]>'9') p=1;
13 else if(a[b-1]<'0'||a[b-1]>'9') p=1;
14 else
15 for(i=1;i<b;i++)
16 {
17 if(a[i]>='0'&&a[i]<='9') p=p-1;
18 else if(a[i]=='+'||a[i]=='-'||a[i]=='*'||a[i]=='/') p=p+1;
19 else if(a[i]!='.') {p=1;break;}
20 }
21 if(a[0]>='0'&&a[0]<='9'&&p==0) printf("Yes\n");
22 else printf("No\n");
23 }
24 }
25
posted @ 2011-04-16 21:16  nightstaker  阅读(470)  评论(1)    收藏  举报