Help!!!!!!!!Wa on test 11!!!!!!!
/*
My program got WA on test 11!!!
What's wrong with my code?
Anyone can help me!!!
*/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define FI first
#define SE second
#define LSON(x) (x<<1)
#define RSON(x) ((x<<1)|1)
#define Benefit(x,y) x=max(x,y)
#define CS const static
#define SORT_CMP(s,l,r,cmp) sort(s+(l),s+(r)+1,cmp)
#define SORT(s,l,r) sort(s+(l),s+(r)+1)
#define MP(x,y) make_pair(x,y)
#define Randomize srand( (unsigned int) time ( NULL ) )
#define INOUT(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout)
using namespace std;
typedef char name[20];
CS int MaxN = 100010 ;
struct word
{
name x;
int val,len;
word() {x[0] = 0; val = 0;}
};
struct Trie
{
Trie * next[26];
word * ans[10];
Trie()
{
for(int i=0;i<26;i++) next[i] = NULL ;
for(int i=0;i<10;i++) ans[i] = NULL ;
}
} * Tree;
word p[MaxN];
name ask;
int n,m,asklen;
void Insert(Trie * x,int _y,int pos)
{
int i; word & y = p[_y];
for(i=0;i<10;i++)
if((x->ans[i]==NULL)||(x->ans[i]->val<y.val)) break;
if(i<10)
{
for(int j=9;j>i;j--)
x -> ans[j] = x->ans[j-1];
x -> ans[i] = p + _y;
}
if(pos!=y.len)
{
int u = y.x[pos] - 'a';
if(!x->next[u]) x -> next[u] = new Trie ;
Insert(x->next[u],_y,pos+1);
}
}
void Init()
{
scanf("%d\n",&n); Tree = new Trie ;
for(int i=1;i<=n;i++)
{
scanf("%s %d\n",p[i].x,&p[i].val); p[i].len=strlen(p[i].x);
Insert(Tree,i,0);
}
}
void Query(Trie * x,int pos)
{
if(pos == asklen)
{
for(int i=0;i<10;i++)
if(x->ans[i]) printf("%s\n",x->ans[i]->x);
else break;
return ;
}
int u = ask[pos] - 'a';
if(x->next[u]) Query(x->next[u],pos+1);
}
void Solve()
{
scanf("%d\n",&m);
while(m--)
{
scanf("%s\n",ask); asklen = strlen(ask) ;
Query(Tree,0); if(m) printf("\n");
}
}
int main()
{
Init(); Solve();
return 0;
}
Edited by author 31.05.2012 14:40
Re: Help!!!!!!!!Wa on test 11!!!!!!!
...wrote Nikolay, 43 solved problems and 6000+-th place, to blablabla, 280 solved problems and place within top 1000.
P.S. And the code style is not great, but quite okay.
Edited by author 19.11.2014 12:32