记录编号 587652 评测结果 AAA
题目名称 [POJ 3630]通讯录 最终得分 100
用户昵称 Gravatarwow草原 是否通过 通过
代码语言 C++ 运行时间 0.194 s
提交时间 2024-04-11 20:20:48 内存使用 10.00 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int s[100010][10],x[100010];
int k,n;
int main(){
    freopen("phonelist1.in","r",stdin);
    freopen("phonelist1.out","w",stdout);
    cin>>k;
    while(k--){
        cin>>n;
        string a;
        char t[10010][20];
        int res=0,ans=0;
        memset(s,0,sizeof(s));
        memset(x,0,sizeof(x));
        for(int j=1;j<=n;j++){
            cin>>t[j];
            int num=0;
            for(int i=0;i<=strlen(t[j])-1;i++){
                if(s[num][t[j][i]-'0']==0){
                    s[num][t[j][i]-'0']=++ans;
                }
                num=s[num][t[j][i]-'0'];
            }x[num]++; 
        }
        for(int j=1;j<=n;j++){
            int num=0;
            for(int i=0;i<=strlen(t[j])-1;i++){
                num=s[num][t[j][i]-'0'];
                if(x[num]>0){
                    if(i!=strlen(t[j])-1)
                    res=x[num];
                    else
                    res=max(x[num]-1,res);
                }
            }
        }
        if(res==0)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    } 
    return 0;
}