409 - Excuses, Excuses!

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

hey some one help me in this

Post by Riyad »

Hey plizzz help me in this problem . i am having compile error all the time . cant find what is wrong ??????/
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

Post by hank »

Hi,

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

Good luck~ 8)
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

Post 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
User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

hey man thanx

Post 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
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

see the input

Post 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:
cuii e
Lon
New poster
Posts: 7
Joined: Sat Jan 31, 2004 12:55 pm

409 runtime error

Post 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");
}
}
my name is Lon
Minilek
Learning poster
Posts: 90
Joined: Tue Jul 27, 2004 9:34 am
Location: Cambridge, MA
Contact:

code tags

Post 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]
Minilek
Learning poster
Posts: 90
Joined: Tue Jul 27, 2004 9:34 am
Location: Cambridge, MA
Contact:

weird

Post by Minilek »

hm..not quite sure what happened there

but anyway, you do it : )
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

409 - Excuses, Excuses

Post by Morning »

punctuation marks [SPMamp".,!?&]
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
Lebedenco
New poster
Posts: 5
Joined: Mon Aug 23, 2004 6:55 am

409 - WA can anybody explain me why?

Post 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.
Last edited by Lebedenco on Sun Feb 20, 2005 3:36 pm, edited 1 time in total.
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post 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.
frankhuhu
New poster
Posts: 30
Joined: Tue Jul 20, 2004 5:22 am
Contact:

Problem 409 Compile Error? Need Help!!

Post 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;
}
frankhuhu
New poster
Posts: 30
Joined: Tue Jul 20, 2004 5:22 am
Contact:

Problem 409 Compile Error? Need Help!!

Post 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;
}
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post 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().
frankhuhu
New poster
Posts: 30
Joined: Tue Jul 20, 2004 5:22 am
Contact:

Post by frankhuhu »

Thanks misof.I have change the head file but still Compile Error! :(
Any more good suggestions?
Post Reply

Return to “Volume 4 (400-499)”