Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

CE是什么情况?

Posted by Manstein at 2016-07-22 09:10:20 on Problem 2503
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxn=1e5+10;
char str[15],str1[maxn][11],str2[maxn][11];
struct Trienode
{
    int t=0;
    Trienode *next2[26];
    Trienode()
    {
        for(int i=0; i<26; i++)
            next2[i]=NULL;

    }

};
Trienode *head;
void buildTrie(char *s,int n)
{int i,index;
    Trienode *p=head;
    for( i=0; i<strlen(s); i++)
    {
         index=s[i]-'a';

        if(!p->next2[index])
        {
            p->next2[index]=new Trienode();

        }

        p=p->next2[index];

    }
 p->t=n;
}
int  searchTrie(char *s)
{  int index,i;
    Trienode *p=head;
    for(i=0; i<strlen(s); i++)
    {
         index=s[i]-'a';
        if(!p->next2[index])
        {

            return -1;

        }

        p=p->next2[index];

    }
    return p->t;

}
int main()
{
    int i = 0, k ;
    head = new Trienode();
    while(gets(str)&&strlen(str)!=0)
    {


        sscanf(str,"%s %s", str1[i], str2[i]);
        buildTrie(str2[i],i);
        i++ ;
    }
    while(gets(str)&&strlen(str)!=0)
    {

        k = searchTrie(str);
        if(k == -1)
            printf("eh\n");
        else
            printf("%s\n", str1[k]);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator