I don't know. He hasn't replied any more.jjtse wrote:does anyone know what was wrong with watershed's code?
10815 - Andy's First Dictionary
Moderator: Board moderators
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
i think i wrote this ---Martin Macko wrote:Are you sure it gives RE? It looks like it should give WA. You write an empty string to the output if the input begins with a non-alpha character.smilitude wrote:code edited....
now what's wrong?
here it checks every single new word, whether they are really new or not
Code: Select all
if(words[i][0]!=' ')
printf("%s\n",words[i]);
fahim
#include <smile.h>
#include <smile.h>
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
That means your program somehow manages to get into an infinite loop which I think not very unlikely in this input format.
You can try my peculiar input strategy for this one.
![:roll:](./images/smilies/icon_rolleyes.gif)
You can try my peculiar input strategy for this one.
Code: Select all
scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);
while(scanf(" %[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf)==1)
{
//process
scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);
}
You should never take more than you give in the circle of life.
10815 RTE help me!!
Code: Select all
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
using namespace std;
struct tree
{
tree();
tree* left;
tree* right;
char* content;
};
tree::tree()
{
left=NULL;
right=NULL;
content=NULL;
}
void build(tree* bitree,char *str,int *count);
void post(tree *bitree);
int main()
{
char str[200];
char *temp=NULL;
tree root;
int i;
int countword=0;
while(countword<5000&&scanf("%s",str)==1)
{
for(i=0;str[i];i++)
{
if('A'<=str[i]&&str[i]<='Z')
{
str[i]=tolower(str[i]);
}
else if(!('a'<=str[i]&&str[i]<='z'))
{
str[i]=' ';
}
}
temp=strtok(str," ");
while(temp!=NULL)
{
build(&root,temp,&countword);
temp=strtok(NULL," ");
}
temp=NULL;
}
post(&root);
return 0;
}
void build(tree* bitree,char *str,int *count)
{
if(bitree->content==NULL)
{
bitree->content=new char [strlen(str)];
(*count)++;
strcpy(bitree->content,str);
}
else if(strcmp(bitree->content,str)<0)
{
if(bitree->left==NULL)
{
bitree->left=new tree;
}
build(bitree->left,str,count);
}
else if(strcmp(bitree->content,str)>0)
{
if(bitree->right==NULL)
{
bitree->right=new tree;
}
build(bitree->right,str,count);
}
return;
}
void post(tree *bitree)
{
if(bitree->right!=NULL)
{
post(bitree->right);
}
cout<<bitree->content<<endl;
if(bitree->left!=NULL)
{
post(bitree->left);
}
return;
}
10815 WHY CE???????!!!!! CRAZY!!!!!!!1
Code: Select all
#include <iostream>
#include <string>
#include <map>
#include <ctype.h>
#include <cstdlib>
using namespace std;
map<string,int> dict;
map<string,int>::iterator itr;
int main()
{
string in;
while(cin>>in)
{
string temp;
temp.clear();
for(int i = 0; i < in.size();i++)
{
temp +=(char)tolower(in[i]);
if(!isalpha(temp[i]))temp[i] = ' ';
}
in.clear();
for(int i = 0; i < temp.size();i++)
if(isalpha(temp[i]))in+=(char)temp[i];
dict[in] = 1;
}
for(itr = dict.begin();itr!=dict.end();itr++)
cout<<itr->first<<endl;
return 0;
}
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: 10815 WHY CE???????!!!!! CRAZY!!!!!!!1
I've just replied you in the other thread you created. (btw, please, never create two or more threads on the same problem.)
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
checked all previous posts and the code seems ok, but it gives WA. would anyone kindly hav a look...
btw, i never used set, thats why i use map here...but it seems ok
thanx in advance.
![:(](./images/smilies/icon_frown.gif)
Code: Select all
cut..
![:roll:](./images/smilies/icon_rolleyes.gif)
thanx in advance.
Last edited by kolpobilashi on Thu Nov 23, 2006 7:29 pm, edited 1 time in total.
Sanjana
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
You missed the problem statement!!!
So add the following line to sort in map<const char *s,int,cmm>
btw, how did you check all posts? Even have you checked Sample I/O!!!
Code: Select all
sorted in alphabetical order
Code: Select all
struct cmm{
bool operator()(const char *str1,const char *str2) const
{
return strcmp(str1,str2)<0;
}
};