Page 2 of 5

hey some one help me in this

Posted: Thu Oct 02, 2003 9:11 am
by Riyad
Hey plizzz help me in this problem . i am having compile error all the time . cant find what is wrong ??????/
Bye
Riyad

Posted: Thu Oct 02, 2003 11:48 am
by hank
Hi,

You can't use the key word "strcmpi".
It is not allowed under ANSI C/C++.

Good luck~ 8)

Posted: Thu Oct 02, 2003 12:04 pm
by hank
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

hey man thanx

Posted: Thu Oct 02, 2003 7:42 pm
by Riyad
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

see the input

Posted: Fri Jan 30, 2004 9:15 pm
by alu_mathics
thanks 2 LAZ boy.
ur sample input is truely helpful for the problem. :roll:
It's like hidden truth in the sample input . :lol:

409 runtime error

Posted: Thu Jul 29, 2004 6:56 am
by Lon
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");
}
}

code tags

Posted: Thu Jul 29, 2004 9:01 am
by Minilek
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]

weird

Posted: Thu Jul 29, 2004 9:02 am
by Minilek
hm..not quite sure what happened there

but anyway, you do it : )

409 - Excuses, Excuses

Posted: Fri Sep 24, 2004 4:13 pm
by Morning
punctuation marks [SPMamp".,!?&]
the punctuation marks should contain "@#",not "SPMamp"
guess something wrong when the text was translated.

409 - WA can anybody explain me why?

Posted: Wed Nov 24, 2004 5:43 am
by Lebedenco
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.

Posted: Sat Dec 04, 2004 11:43 am
by A1
There is error in your code so I could not compile your code!
Nobody is going to help you by fixing you code error. I think one should not post their PE code here but when you are in WA - you can post it.

Problem 409 Compile Error? Need Help!!

Posted: Tue Feb 08, 2005 8:47 am
by frankhuhu
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;
}

Problem 409 Compile Error? Need Help!!

Posted: Thu Feb 10, 2005 11:49 am
by frankhuhu
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;
}

Posted: Thu Feb 10, 2005 2:36 pm
by misof
As a rule of thumb, don't mix C, old C++ and new C++ header files. In your case, instead of

Code: Select all

#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cctype>
use

Code: Select all

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
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().

Posted: Thu Feb 10, 2005 4:51 pm
by frankhuhu
Thanks misof.I have change the head file but still Compile Error! :(
Any more good suggestions?