494 - Kindergarten Counting Game
Moderator: Board moderators
-
- New poster
- Posts: 1
- Joined: Mon Feb 24, 2003 10:10 am
494 Help me
[cpp]
why did I get a runtime error?
/* @begin_of_source_code */
/* @JUDGE_ID: 27962FX 494 C++ */
#include<stdio.h>
#include<string.h>
int main()
{
char sen[100];
int a=0,b,count=0;
while(scanf("%c",&sen[a])!=EOF)
{
if(sen[a]=='\n')
{
a=0;
do
{
if(sen[a]==' '||!(sen>='a'&&sen<='z'||sen>='A'&&sen<='Z'))
{
b=a;
while(sen!='\n')
{
if((sen>='a'&&sen<='z'||sen>='A'&&sen<='Z')&&(sen[b-1]==' '))
{
++count;
break;
}
++b;
}
a=b;
}
++a;
}while(sen[a]!='\n');
printf("%d\n",count+1);
count=0;
a=0;
}
++a;
}
return 0;
}
/* @end_of_source_code */
[/cpp]
why did I get a runtime error?
/* @begin_of_source_code */
/* @JUDGE_ID: 27962FX 494 C++ */
#include<stdio.h>
#include<string.h>
int main()
{
char sen[100];
int a=0,b,count=0;
while(scanf("%c",&sen[a])!=EOF)
{
if(sen[a]=='\n')
{
a=0;
do
{
if(sen[a]==' '||!(sen>='a'&&sen<='z'||sen>='A'&&sen<='Z'))
{
b=a;
while(sen!='\n')
{
if((sen>='a'&&sen<='z'||sen>='A'&&sen<='Z')&&(sen[b-1]==' '))
{
++count;
break;
}
++b;
}
a=b;
}
++a;
}while(sen[a]!='\n');
printf("%d\n",count+1);
count=0;
a=0;
}
++a;
}
return 0;
}
/* @end_of_source_code */
[/cpp]
Increase ur array size
I think, you are new in this business...
Always try to use bigger arrays...that will use some extra memory, but your program will never get RTE...
in this case, you should use an array size of 1,000,000...
if it doesn't work, try decreasing a little....
Razib
Always try to use bigger arrays...that will use some extra memory, but your program will never get RTE...
in this case, you should use an array size of 1,000,000...
if it doesn't work, try decreasing a little....
Razib
Do or do not, there is no try.
494 Why WA?
i don't understand.
i also tried many times, who can help me?
i shall be grateful.
[cpp]#include <iostream.h>
#define Max 5000
char S[Max];
void main()
{
while(cin.getline(S,Max))
{
int length=cin.gcount()-1; // delete the return key
int count=0,i=0;
while(i<length)
{
while(S==' ') // Chop off ' ' before character
i++;
while(S!=' ')
{
if(i==length) break;
if(S>='a'&&S<='z'||S>='A'&&S<='Z')
i++;
else break;
}
if(S==' '||i==length) count++; // Indeed the word case including last case
while(S!=' ')
{
if(i==length) break;
i++;
}
}
cout<<count<<endl;
}
}[/cpp]
i also tried many times, who can help me?
i shall be grateful.
[cpp]#include <iostream.h>
#define Max 5000
char S[Max];
void main()
{
while(cin.getline(S,Max))
{
int length=cin.gcount()-1; // delete the return key
int count=0,i=0;
while(i<length)
{
while(S==' ') // Chop off ' ' before character
i++;
while(S!=' ')
{
if(i==length) break;
if(S>='a'&&S<='z'||S>='A'&&S<='Z')
i++;
else break;
}
if(S==' '||i==length) count++; // Indeed the word case including last case
while(S!=' ')
{
if(i==length) break;
i++;
}
}
cout<<count<<endl;
}
}[/cpp]
Why 494 WA? Could you help me?
Sorry, but I don't understand why it is wrong!!!
Could you help me? Thank you very much!
[c]#include<stdio.h>
#include<string.h>
int count(char str[])
{
register int sum=0,i;
register char *p;
p=strtok(str," ");
do{
for(i=0;*(p+i)!=NULL;i++)
if((*(p+i)>96&&*(p+i)<123)||(*(p+i)>64&&*(p+i)<91)){
sum++;
break;
}
p=strtok(NULL," ");
}while(p);
return sum;
}
void main(void)
{
char str[255];
while(gets(str))
printf("%d\n",count(str));
}[/c]
Could you help me? Thank you very much!
![:cry:](./images/smilies/icon_cry.gif)
[c]#include<stdio.h>
#include<string.h>
int count(char str[])
{
register int sum=0,i;
register char *p;
p=strtok(str," ");
do{
for(i=0;*(p+i)!=NULL;i++)
if((*(p+i)>96&&*(p+i)<123)||(*(p+i)>64&&*(p+i)<91)){
sum++;
break;
}
p=strtok(NULL," ");
}while(p);
return sum;
}
void main(void)
{
char str[255];
while(gets(str))
printf("%d\n",count(str));
}[/c]
I still don't understand!
Sorry, I still don't understand. Could you explain it more clearly?
Thanks, I've solved it!
Thanks, I've solved it!
[c]#include<stdio.h>
#include<string.h>
void main(void)
{
char p[255];
register int sum,i;
while(gets(p)){
for(sum=0,i=0;*(p+i)!=NULL;i++)
if(((*(p+i)>96&&*(p+i)<123)||(*(p+i)>64&&*(p+i)<91))&&(*(p+i+1)<65||*(p+i+i)>122||(*(p+i+i)>90&&*(p+i+i)<97)))
sum++;
printf("%d\n",sum);
}
}[/c]
![:D](./images/smilies/icon_biggrin.gif)
[c]#include<stdio.h>
#include<string.h>
void main(void)
{
char p[255];
register int sum,i;
while(gets(p)){
for(sum=0,i=0;*(p+i)!=NULL;i++)
if(((*(p+i)>96&&*(p+i)<123)||(*(p+i)>64&&*(p+i)<91))&&(*(p+i+1)<65||*(p+i+i)>122||(*(p+i+i)>90&&*(p+i+i)<97)))
sum++;
printf("%d\n",sum);
}
}[/c]
494 wa ,plizzzzzzzzzzz help
i cant understand what is wrong in my code. i am having trouble understanding the input style. is this a valid input:
.........as.........asdf..........???????????............qwer
.................aaaaaa....................bbbbbbbbbbbbb..
if these input format is right what modification in my code should be done.plizzzzzzzzzzz help .here is my code:
[c]
#include<stdio.h>
#define size 100000
int main(){
char input[size],ch;
register int i,flag,fch;
int count;
while(gets(input)){
count=0;
flag=1,fch=1;
for(i=0;input!='\0';i++){
ch=input;
if(ch==32){
if(flag==0&& fch==1){
count++;
flag=1;
}
}
else if(ch!=32){
if(flag==1){
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
fch=1;
flag=0;
}
else{
fch=0;
}
}
}
}
if(flag==0&&fch==1)
count+=1;
printf("%d\n",count);
}
return 0;
}
[/c]
thanx is advance .looking for help.
Riyad
.........as.........asdf..........???????????............qwer
.................aaaaaa....................bbbbbbbbbbbbb..
if these input format is right what modification in my code should be done.plizzzzzzzzzzz help .here is my code:
[c]
Code: Select all
#define size 100000
int main(){
char input[size],ch;
register int i,flag,fch;
int count;
while(gets(input)){
count=0;
flag=1,fch=1;
for(i=0;input!='\0';i++){
ch=input;
if(ch==32){
if(flag==0&& fch==1){
count++;
flag=1;
}
}
else if(ch!=32){
if(flag==1){
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
fch=1;
flag=0;
}
else{
fch=0;
}
}
}
}
if(flag==0&&fch==1)
count+=1;
printf("%d\n",count);
}
return 0;
}
[/c]
thanx is advance .looking for help.
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
Yes, they are valid input. Reread this line from the problem:
This does not necessarily mean that they must be separated by a space, just anything that is a non-letter. Thus your inputs above should return 3 and 2 respectively.A "word'' is defined as a consecutive sequence of letters (upper and/or lower case).
thanx a lot
thanx a lot friend . got it ac . i could not understand the input format . got it now. thanx once again.
bye
Riyad
![:lol:](./images/smilies/icon_lol.gif)
![:D](./images/smilies/icon_biggrin.gif)
bye
Riyad
![:)](./images/smilies/icon_smile.gif)
![:lol:](./images/smilies/icon_lol.gif)
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
494 run time error
why run time error.i m frustrated.plz help me
[c]
#include<stdio.h>
#include<ctype.h>
main()
{
char t[12000];
char c,*x;
int i=0,check=0,count=0;
while((c=getchar())!=EOF)
{
t[i++]=c;
if(c=='\n')
{
t='\0';
x=t;
while(*x)
{
while(isalpha(*x))
{
if(*x=='\0')
break;
check=1;
x++;
}
while(isdigit(*x))
{
if(*x=='\0')
break;
check=1;
x++;
}
if(isspace(*x))
{
if(check==1)
{
count++;
check=0;
}
x++;
}
if(!isalpha(*x))
{
if(*x=='\n'||*x=='\0')
{
printf("%d\n",count);
count=0;
check=0;
x++;
break;
}
}
}
i=0;
}
}
}
[\c]
[c]
#include<stdio.h>
#include<ctype.h>
main()
{
char t[12000];
char c,*x;
int i=0,check=0,count=0;
while((c=getchar())!=EOF)
{
t[i++]=c;
if(c=='\n')
{
t='\0';
x=t;
while(*x)
{
while(isalpha(*x))
{
if(*x=='\0')
break;
check=1;
x++;
}
while(isdigit(*x))
{
if(*x=='\0')
break;
check=1;
x++;
}
if(isspace(*x))
{
if(check==1)
{
count++;
check=0;
}
x++;
}
if(!isalpha(*x))
{
if(*x=='\n'||*x=='\0')
{
printf("%d\n",count);
count=0;
check=0;
x++;
break;
}
}
}
i=0;
}
}
}
[\c]