Submission #3814318


Source Code Expand

#include<bits/stdc++.h>
#define N 10050
using namespace std;
int n,m,z,tot,bh[55];
char s[55],s1[55];
struct trie{int usd,cnt,cld[27];}tree[N];
void add(){     //向trie树中加单词
    int let=0,leth=strlen(s),rot=0;
    while(tree[rot].cld[s[let]-'A'])
    rot=tree[rot].cld[s[let]-'A'],let++;
    while(let^leth) rot=(tree[rot].cld[s[let]-'A']=++tot),let++;
    tree[rot].usd=1;tree[rot].cnt++;
}
void find(int u,int num){  //找
    for(int i=0;i^27;i++)  //枚举所有孩子
    if(tree[u].cld[i]){
        s1[num]=i+'A';   //存下字母
        if(tree[tree[u].cld[i]].usd) z+=tree[tree[u].cld[i]].cnt; //若此处有单词,统计数加。
        if(z>=7) {puts(s1);return;} //若统计次数大于等于7,输出。
        find(tree[u].cld[i],num+1); //找孩子所包含的字符串
        if(z>=7) return;  //搜过孩子后若已输出,返回。
    }s1[num]=0;  //字母清空
}
int main(){
    while(scanf("%s",s)!=EOF) add();  //读入
    find(0,0);  //找字典序第7大的。
    return 0;   //走人
}

Submission Info

Submission Time
Task A - 天下一人力比較
User luogu_bot2
Language C++ (GCC 5.4.1)
Score 20
Code Size 1061 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 20 / 20
Status
AC × 1
Set Name Test Cases
All answer
Case Name Status Exec Time Memory
answer AC 1 ms 256 KB