409 - Excuses, Excuses!
Moderator: Board moderators
hey some one help me in this
Hey plizzz help me in this problem . i am having compile error all the time . cant find what is wrong ??????/
Bye
Riyad
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
You can use the following code to replace that function.
[c]
#include "string.h"
#include "ctype.h"
int strcmpi(char *a,char *b)
{
int i;
if( strlen(a)>strlen(b) ) return 1;
else if( strlen(a)<strlen(b) ) return -1;
for(i=0;i<strlen(a);i++){
if( toupper(a)>toupper(b) ) return 1;
else if( toupper(a)<toupper(b) ) return -1;
}
return 0;
}[/c]
Good luck~![:P](./images/smilies/icon_razz.gif)
[c]
#include "string.h"
#include "ctype.h"
int strcmpi(char *a,char *b)
{
int i;
if( strlen(a)>strlen(b) ) return 1;
else if( strlen(a)<strlen(b) ) return -1;
for(i=0;i<strlen(a);i++){
if( toupper(a)>toupper(b) ) return 1;
else if( toupper(a)<toupper(b) ) return -1;
}
return 0;
}[/c]
Good luck~
![:P](./images/smilies/icon_razz.gif)
hey man thanx
thanx hank ,
u helped me a lot . i am successful to remove the compile error after ur suggestion and using u r function . hey but as a matter of regret getting wa for some reason . cant find it why ??
sorry for being my stupid and not to check the function strcmpi () in the ansi c/c++ list.
thanx once again
Bye
Riyad
u helped me a lot . i am successful to remove the compile error after ur suggestion and using u r function . hey but as a matter of regret getting wa for some reason . cant find it why ??
sorry for being my stupid and not to check the function strcmpi () in the ansi c/c++ list.
thanx once again
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
-
- Learning poster
- Posts: 55
- Joined: Sat Jan 24, 2004 9:30 pm
- Location: Chittagong
- Contact:
see the input
thanks 2 LAZ boy.
ur sample input is truely helpful for the problem.
It's like hidden truth in the sample input .![:lol:](./images/smilies/icon_lol.gif)
ur sample input is truely helpful for the problem.
![:roll:](./images/smilies/icon_rolleyes.gif)
It's like hidden truth in the sample input .
![:lol:](./images/smilies/icon_lol.gif)
cuii e
409 runtime error
This is my code!!
who can tell me why get runtime error!!!
thanks
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char word[1000],key[50][100],re[50][100],ans[50][100],*p;
void clear()
{
int i,j;
for(i=0;i<=50;i++)
for(j=0;j<=100;j++)
ans[j]=re[j]=key[j]='\0';
}
int restore(int j)
{
int v;
for(v=0;re[j][v]!='\0';v++)
key[j][v]=re[j][v];
}
void main()
{
int time[100],dir[100];
int k,e,c,len,i,j,max,times=0;
while(scanf("%d %d",&k,&e)==2)
{
getchar();
times++;
max=c=0;
clear();
for(i=0;i<=100;i++)
dir=time=0;
while(c<(k+e))
{
gets(word);
len=strlen(word);
for(i=0;i<len;i++)
{
ans[c]=word;
if(ispunct(word)==0)
{
word=toupper(word);
re[c][i]=key[c][i]=word[i];
}
else
re[c][i]=key[c][i]=' ';
}
c++;
}
for(i=0;i<k;i++)
{
for(j=k;j<(k+e);j++)
{
for(p=strtok(key[j]," ");p;p=strtok(NULL," "))
{
if((!strcmp(p,key[i]))&&dir[i]==0)
{
time[j]++;
dir[i]=1;
}
}
if(time[j]>max)
max=time[j];
dir[i]=0;
restore(j);
}
}
printf("Excuse Set #%d\n",times);
for(i=k;i<(k+e);i++)
{
if(time[i]==max)
printf("%s\n",ans[i]);
}
printf("\n");
}
}
who can tell me why get runtime error!!!
thanks
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char word[1000],key[50][100],re[50][100],ans[50][100],*p;
void clear()
{
int i,j;
for(i=0;i<=50;i++)
for(j=0;j<=100;j++)
ans[j]=re[j]=key[j]='\0';
}
int restore(int j)
{
int v;
for(v=0;re[j][v]!='\0';v++)
key[j][v]=re[j][v];
}
void main()
{
int time[100],dir[100];
int k,e,c,len,i,j,max,times=0;
while(scanf("%d %d",&k,&e)==2)
{
getchar();
times++;
max=c=0;
clear();
for(i=0;i<=100;i++)
dir=time=0;
while(c<(k+e))
{
gets(word);
len=strlen(word);
for(i=0;i<len;i++)
{
ans[c]=word;
if(ispunct(word)==0)
{
word=toupper(word);
re[c][i]=key[c][i]=word[i];
}
else
re[c][i]=key[c][i]=' ';
}
c++;
}
for(i=0;i<k;i++)
{
for(j=k;j<(k+e);j++)
{
for(p=strtok(key[j]," ");p;p=strtok(NULL," "))
{
if((!strcmp(p,key[i]))&&dir[i]==0)
{
time[j]++;
dir[i]=1;
}
}
if(time[j]>max)
max=time[j];
dir[i]=0;
restore(j);
}
}
printf("Excuse Set #%d\n",times);
for(i=k;i<(k+e);i++)
{
if(time[i]==max)
printf("%s\n",ans[i]);
}
printf("\n");
}
}
my name is Lon
code tags
you should really use the code tags
[c]#include<stdio.h>
#include<string.h>
#include<ctype.h>
char word[1000],key[50][100],re[50][100],ans[50][100],*p;
void clear()
{
int i,j;
for(i=0;i<=50;i++)
for(j=0;j<=100;j++)
ans[j]=re[j]=key[j]='\0';
}
int restore(int j)
{
int v;
for(v=0;re[j][v]!='\0';v++)
key[j][v]=re[j][v];
}
void main()
{
int time[100],dir[100];
int k,e,c,len,i,j,max,times=0;
while(scanf("%d %d",&k,&e)==2)
{
getchar();
times++;
max=c=0;
clear();
for(i=0;i<=100;i++)
dir=time=0;
while(c<(k+e))
{
gets(word);
len=strlen(word);
for(i=0;i<len;i++)
{
ans[c]=word;
if(ispunct(word)==0)
{
word=toupper(word);
re[c][i]=key[c][i]=word[i];
}
else
re[c][i]=key[c][i]=' ';
}
c++;
}
for(i=0;i<k;i++)
{
for(j=k;j<(k+e);j++)
{
for(p=strtok(key[j]," ");p;p=strtok(NULL," "))
{
if((!strcmp(p,key[i]))&&dir[i]==0)
{
time[j]++;
dir[i]=1;
}
}
if(time[j]>max)
max=time[j];
dir[i]=0;
restore(j);
}
}
printf("Excuse Set #%d\n",times);
for(i=k;i<(k+e);i++)
{
if(time[i]==max)
printf("%s\n",ans[i]);
}
printf("\n");
}
}[/c]
[c]#include<stdio.h>
#include<string.h>
#include<ctype.h>
char word[1000],key[50][100],re[50][100],ans[50][100],*p;
void clear()
{
int i,j;
for(i=0;i<=50;i++)
for(j=0;j<=100;j++)
ans[j]=re[j]=key[j]='\0';
}
int restore(int j)
{
int v;
for(v=0;re[j][v]!='\0';v++)
key[j][v]=re[j][v];
}
void main()
{
int time[100],dir[100];
int k,e,c,len,i,j,max,times=0;
while(scanf("%d %d",&k,&e)==2)
{
getchar();
times++;
max=c=0;
clear();
for(i=0;i<=100;i++)
dir=time=0;
while(c<(k+e))
{
gets(word);
len=strlen(word);
for(i=0;i<len;i++)
{
ans[c]=word;
if(ispunct(word)==0)
{
word=toupper(word);
re[c][i]=key[c][i]=word[i];
}
else
re[c][i]=key[c][i]=' ';
}
c++;
}
for(i=0;i<k;i++)
{
for(j=k;j<(k+e);j++)
{
for(p=strtok(key[j]," ");p;p=strtok(NULL," "))
{
if((!strcmp(p,key[i]))&&dir[i]==0)
{
time[j]++;
dir[i]=1;
}
}
if(time[j]>max)
max=time[j];
dir[i]=0;
restore(j);
}
}
printf("Excuse Set #%d\n",times);
for(i=k;i<(k+e);i++)
{
if(time[i]==max)
printf("%s\n",ans[i]);
}
printf("\n");
}
}[/c]
weird
hm..not quite sure what happened there
but anyway, you do it : )
but anyway, you do it : )
409 - Excuses, Excuses
punctuation marks [SPMamp".,!?&]
the punctuation marks should contain "@#",not "SPMamp"
guess something wrong when the text was translated.
the punctuation marks should contain "@#",not "SPMamp"
guess something wrong when the text was translated.
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
409 - WA can anybody explain me why?
I know it is supposed to be a simple problem but I'm getting WA and I just can't figure out why! I don't like to post code but anyway here it is. The idea is to get rid of any char that is not alpha and then using a stringstream (similar to sscanf) retrieve every single word remaining and compare to the words in the dictionary.
(code removed)
Thanks in advance.
(code removed)
Thanks in advance.
Last edited by Lebedenco on Sun Feb 20, 2005 3:36 pm, edited 1 time in total.
Problem 409 Compile Error? Need Help!!
I don't know why it says Compile Error.The code compile well on my VC++6.0 and GCC.Is there anyone who can help me?Thanks !
Here is my code:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
int main()
{
int k,e,i,j,m;
int space_cnt[50],kase=1;
char keyword[50][50],excuse[50][500],input[50][500];
while (cin>>k>>e)
{
for (i=0;i<50;i++) space_cnt=1;
for (i=0;i<k;i++) cin>>keyword;
scanf("\n");
for (i=0;i<e;i++) cin.getline(excuse,500);
cout<<"Excuse Set #"<<kase++<<endl;
for (i=0;i<e;i++)
{
strcpy(input,excuse);
for (j=0;input[j];j++)
if (!isalpha(input[j])) input[j]=' ';
}
for (i=0;i<e;i++)
{
for (j=0;input[j];j++)
if (isspace(input[j])&&isalpha(input[i][j+1])) space_cnt[i]++;
}
int cnt[100];
memset(cnt,0,sizeof(cnt));
for (i=0;i<e;i++)
{
char *p;
p=strtok(input[i]," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
for (m=0;m<space_cnt[i]-1;m++)
{
p=strtok(NULL," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
}
}
int max=0;
for (i=0;i<e;i++)
if (cnt[i]>max) max=cnt[i];
for (i=0;i<e;i++)
if (cnt[i]==max) cout<<excuse[i]<<endl;
cout<<endl;
}
return 0;
}
Here is my code:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
int main()
{
int k,e,i,j,m;
int space_cnt[50],kase=1;
char keyword[50][50],excuse[50][500],input[50][500];
while (cin>>k>>e)
{
for (i=0;i<50;i++) space_cnt=1;
for (i=0;i<k;i++) cin>>keyword;
scanf("\n");
for (i=0;i<e;i++) cin.getline(excuse,500);
cout<<"Excuse Set #"<<kase++<<endl;
for (i=0;i<e;i++)
{
strcpy(input,excuse);
for (j=0;input[j];j++)
if (!isalpha(input[j])) input[j]=' ';
}
for (i=0;i<e;i++)
{
for (j=0;input[j];j++)
if (isspace(input[j])&&isalpha(input[i][j+1])) space_cnt[i]++;
}
int cnt[100];
memset(cnt,0,sizeof(cnt));
for (i=0;i<e;i++)
{
char *p;
p=strtok(input[i]," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
for (m=0;m<space_cnt[i]-1;m++)
{
p=strtok(NULL," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
}
}
int max=0;
for (i=0;i<e;i++)
if (cnt[i]>max) max=cnt[i];
for (i=0;i<e;i++)
if (cnt[i]==max) cout<<excuse[i]<<endl;
cout<<endl;
}
return 0;
}
Problem 409 Compile Error? Need Help!!
I don't know why it says Compile Error.The code compile well on my VC++6.0 and GCC.Is there anyone who can help me?Thanks !
Here is my code:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
int main()
{
int k,e,i,j,m;
int space_cnt[50],kase=1;
char keyword[50][50],excuse[50][500],input[50][500];
while (cin>>k>>e)
{
for (i=0;i<50;i++) space_cnt=1;
for (i=0;i<k;i++) cin>>keyword;
scanf("\n");
for (i=0;i<e;i++) cin.getline(excuse,500);
cout<<"Excuse Set #"<<kase++<<endl;
for (i=0;i<e;i++)
{
strcpy(input,excuse);
for (j=0;input[j];j++)
if (!isalpha(input[j])) input[j]=' ';
}
for (i=0;i<e;i++)
{
for (j=0;input[j];j++)
if (isspace(input[j])&&isalpha(input[j+1])) space_cnt[i]++;
}
int cnt[100];
memset(cnt,0,sizeof(cnt));
for (i=0;i<e;i++)
{
char *p;
p=strtok(input[i]," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
for (m=0;m<space_cnt[i]-1;m++)
{
p=strtok(NULL," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
}
}
int max=0;
for (i=0;i<e;i++)
if (cnt[i]>max) max=cnt[i];
for (i=0;i<e;i++)
if (cnt[i]==max) cout<<excuse[i]<<endl;
cout<<endl;
}
return 0;
}
Here is my code:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
int main()
{
int k,e,i,j,m;
int space_cnt[50],kase=1;
char keyword[50][50],excuse[50][500],input[50][500];
while (cin>>k>>e)
{
for (i=0;i<50;i++) space_cnt=1;
for (i=0;i<k;i++) cin>>keyword;
scanf("\n");
for (i=0;i<e;i++) cin.getline(excuse,500);
cout<<"Excuse Set #"<<kase++<<endl;
for (i=0;i<e;i++)
{
strcpy(input,excuse);
for (j=0;input[j];j++)
if (!isalpha(input[j])) input[j]=' ';
}
for (i=0;i<e;i++)
{
for (j=0;input[j];j++)
if (isspace(input[j])&&isalpha(input[j+1])) space_cnt[i]++;
}
int cnt[100];
memset(cnt,0,sizeof(cnt));
for (i=0;i<e;i++)
{
char *p;
p=strtok(input[i]," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
for (m=0;m<space_cnt[i]-1;m++)
{
p=strtok(NULL," ");
if (p)
{
for (j=0;j<k;j++)
if (strcmpi(p,keyword[j])==0) cnt[i]++;
}
}
}
int max=0;
for (i=0;i<e;i++)
if (cnt[i]>max) max=cnt[i];
for (i=0;i<e;i++)
if (cnt[i]==max) cout<<excuse[i]<<endl;
cout<<endl;
}
return 0;
}
As a rule of thumb, don't mix C, old C++ and new C++ header files. In your case, instead of
use
The last line is important. Some compilers do this automatically, g++ doesn't. The C++ header files (you included cctype) define their symbols and functions in the std namespace. Thus g++ couldn't find the function isalpha() you use in your code -- without the "using namespace std;" you would have to write std::isalpha().
Code: Select all
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;