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

就算t死了,也要把这道题a了

Posted by 2017401349fei at 2018-09-03 17:30:40 on Problem 3630
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
bool end1;
node *next[10];
int num;
void init(){
    end1=false;
    for(int i=0;i<10;i++)
        next[i]=NULL;
    num=0;
}
};
node temp[100000];
node *root;
int flag,count1;
void insert1(char *s)
{
    //int len=strlen(s);
    node *p=root;
    for(int i=0;s[i];i++)
    {
        int a=s[i]-'0';
        if(p->next[a]==NULL)
            p->next[a]=temp+count1,count1++;
        p=p->next[a];
        p->num++;
        if(p->end1)
        {
            flag=1;
            return;
        }
    }
    p->end1=true;
    if(p->num>1)
    {
        flag=1;
        return;
    }
}
void init()
{
    for(int i=0;i<100000;i++)
        temp[i].init();
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        count1=0;
        init();
        root=temp+count1;
        count1++;
        scanf("%d",&n);
        flag=0;
        char c[20];
        for(int i=0;i<n;i++)
        {
            scanf("%s",c);
            if(!flag)
                insert1(c);
        }
        if(flag)
            printf("NO\n");
        else printf("YES\n");

    }
    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