Posted: Sat Dec 10, 2005 3:51 pm
I don't know. He hasn't replied any more.jjtse wrote:does anyone know what was wrong with watershed's code?
I don't know. He hasn't replied any more.jjtse wrote:does anyone know what was wrong with watershed's code?
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
After you got accepted, please, remove the code to make the topic more readable and not to create unnecessary spoilers.jjtse wrote:Thanks. I got AC.
Are you sure these are all delimiters that are in the input?roticv wrote:I did according to what was mentioned above, but I still keep getting WA.
code wrote:................pch = strtok(str," :\\;,./\n\t\'"`~!@#$%^&*-_+=1234567890");
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]);
Code: Select all
scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);
while(scanf(" %[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf)==1)
{
//process
scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);
}
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;
}
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;
}
Code: Select all
cut..
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;
}
};