well, it seems quite wiered!! i've compiled the code you pasted above using two different compilers and tested them using the above input and got the same following output:
abcd
There is no such word.
abcd
There is no such word.
and i was so confused that i carefully checked your code afterwards, and got a bug for which this happend. so, it seems you might have changed something in the code posted above otherwise it is impossible to get the output you posted.
about the bug, in your code there's a part as follows:
[c]if(nl) printf("\n");
else nl=1;
[/c]
i just cut this segment and pasted it just above the statement:
[c]inorder(root,num);
[/c]
and after this change your code gave correct output.
i'm quite sure that after making the same change in your code you'll get AC.
As an aggregate, all the string concatentations are fairly expensive:
[cpp]text = text + " " + line;
...
word+=(tolower(ch));[/cpp]
I'm also not familiar with how the sort() function is implemented for a list, but since a list isn't random access, I suspect there are a some inefficiencies that, say, using a vector would eliminate.
I got WA in this prob. But I couldnt find any prob in my code. Can anyone help me?
Here is my code
[c]
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
My program is now ok for ur test case. But i got wa again.
If u have enough time then pls look through my code.
Or if u can't then give me more test case.
Here is few lines from your code
[cpp]char inp[100];
/*freopen("c:\\inp.txt","r",stdin);*/
while(scanf("%d",&n)==1)
{
i=0;
while(scanf("%s",&inp)==1)
[/cpp]
Don' you think you made a very basic mistake here.
Shamim Bahi, I didn't find any mistake in there.
What can i do?
I change my that portion of code with that. but the result is same.
[c]
char inp[100];
while(scanf("%d",&n)==1)
I have TLE in this problem because I use in a program
g += tolower(c);
in a part of code
string g;
char c;
vector<pair<string,int> > v;
while(scanf("%c",&c))
{
if (!isalpha(c))
{
if (g.size() > 0)
{
if (g == "endoftext") break;
i = Find(g);
if (i < 0) v.push_back(make_pair(g,1));
else v[i].second++;
g = "";
}
continue;
}
g += tolower(c);
}
How to increase spped?
If I use not string, but char*, then I have a question:
if I have char a[1000], where I put a word. How to convert
it into string?
Though you are using qsort(), your complexity is actually O(n^2). Because you are listing the words first. And while listing you are checking whether this current word exists or not by checking all the other listed words. Just change this idea. First, list all the words. So, there can be duplicate words in the list. Sort them. Then you can find all the non-duplicate words and their frequency in just O(n) time. So, the total complexity will be O(n*log(n)), and which is an acceptable complexity for this problem.