|
|
back to board #include<stdio.h> void main(void) { int ch,c,start_s,start_w; c=0; start_s=1,start_w=0; while((ch=getchar())!=-1) { if(ch=='\n')continue; if(ch=='.' || ch=='?' || ch=='!') {start_s=1;continue;} if(ch==' '){start_w=1;continue;} if(start_s && ch>='a' && ch<='z') {start_s=start_w=0;c++;continue;} else { if(!start_s && start_w && ch>='A' && ch<='Z') c++; start_w=0; start_s=0; } } printf("%d\n",c); } Well, when you encounter a line break you should change start_w to 0 as a line break is a word separator. Good luck. Thanks to Ivan Georgiev But still I am getting WA. Would you check it again. Here the modified code #include<stdio.h> void main(void) { int ch,c,start_s,start_w; freopen("D:\\1038.in","rt",stdin);
c=0; start_s=1,start_w=0; while((ch=getchar())!=-1) { if(ch=='\n'){start_s=1,start_w=0;continue;} if(ch=='.' || ch=='?' || ch=='!') {start_s=1;continue;} if(ch==' ') {start_w=1;continue;} if(start_s && ch>='a' && ch<='z') {start_s=start_w=0;c++;continue;} else { if(!start_s && start_w && ch>='A' && ch<='Z') c++; start_w=0;start_s=0; } } printf("%d\n",c); } > Thanks to Ivan Georgiev > But still I am getting WA. > Would you check it again. > > Here the modified code > > #include<stdio.h> > > void main(void) > { > int ch,c,start_s,start_w; > freopen("D:\\1038.in","rt",stdin); > > c=0; > start_s=1,start_w=0; > while((ch=getchar())!=-1) > { > if(ch=='\n'){start_s=1,start_w=0;continue;} > if(ch=='.' || ch=='?' || ch=='!') > {start_s=1;continue;} > if(ch==' ') > {start_w=1;continue;} > if(start_s && ch>='a' && ch<='z') > {start_s=start_w=0;c++;continue;} > else > { > if(!start_s && start_w && ch>='A' && ch<='Z') > c++; > start_w=0;start_s=0; > } > } > printf("%d\n",c); > } > > Thanks to Ivan Georgiev > But still I am getting WA. > Would you check it again. > > Here the modified code > > #include<stdio.h> > > void main(void) > { > int ch,c,start_s,start_w; > freopen("D:\\1038.in","rt",stdin); > > c=0; > start_s=1,start_w=0; > while((ch=getchar())!=-1) > { > if(ch=='\n'){start_s=1,start_w=0;continue;} > if(ch=='.' || ch=='?' || ch=='!') > {start_s=1;continue;} > if(ch==' ') > {start_w=1;continue;} > if(start_s && ch>='a' && ch<='z') > {start_s=start_w=0;c++;continue;} > else > { > if(!start_s && start_w && ch>='A' && ch<='Z') > c++; > start_w=0;start_s=0; > } > } > printf("%d\n",c); > } > Words can be separated by more than one space (and other characters as well). I think that's the problem. > Thanks to Ivan Georgiev > But still I am getting WA. > Would you check it again. > > Here the modified code > > #include<stdio.h> > > void main(void) > { > int ch,c,start_s,start_w; > freopen("D:\\1038.in","rt",stdin); > > c=0; > start_s=1,start_w=0; > while((ch=getchar())!=-1) > { > if(ch=='\n'){start_s=1,start_w=0;continue;} > if(ch=='.' || ch=='?' || ch=='!') > {start_s=1;continue;} > if(ch==' ') > {start_w=1;continue;} > if(start_s && ch>='a' && ch<='z') > {start_s=start_w=0;c++;continue;} > else > { > if(!start_s && start_w && ch>='A' && ch<='Z') > c++; > start_w=0;start_s=0; > } > } > printf("%d\n",c); > } > Words can be separated by more than one space (and other characters as well). I think that's the problem. > > Thanks to Ivan Georgiev Can you give any judge data for that it gives WA. I think that will be good for me to judge. > > > Thanks to Ivan Georgiev > > Can you give any judge data for that it gives WA. > I think that will be good for me to judge. Try this tests: The old vaRsag my Antonesgh..%sg4mahng 35tsavx 3mnkxb o o oo AA gfsd . sdgw a aA Aa The answer is 5 I am good and evil. i $JHBFS# dreams dreA MS and DREAMS.222 The answer is 12 I think that you cann't use symbols:'@','#','$','%','&'... Input contains a text that consists of capital and small letters of the Latin alphabet (A–Z, a–z), punctuation marks (.,;:-!?) and spaces. Thank you very much.I think I can accept it now. > Try this tests: > > The old vaRsag my > Antonesgh..%sg4mahng 35tsavx > 3mnkxb o o oo AA gfsd . sdgw a > aA > Aa My AC code returns 4. Edited by author 06.06.2007 13:07 strange... but there are 5 mistakes: The old va[R]sag my Antonesgh..%[s]g4mahng 35tsavx 3mnkxb o o oo A[A] gfsd . [s]dgw a a[A] Aa |
|
|