LOJ10052

LOJ10052

同LOJ10049,就是读入有毒。。

#include
#define gt() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
#define isnum(ch) (ch>='0'&&ch<='9')
using namespace std;
static char buf[1000000],*p1=buf,*p2=buf;
const char Ans[2][10]={{"YES\n"},{"NO\n"}};
const int maxn=(1e5)+5,maxl=3;
int T,n,tot;int s[maxn][maxl];bool flg,id[maxn];
int main(){
    for(int i=1;;i++){
        tot=flg=0;char ch=gt();
        while(!isnum(ch)){if(ch==EOF) break;ch=gt();}
        if(ch==EOF) break;
        int rot=0;bool tag,pas;s[rot][0]=s[rot][1]=0;
        while(1){
            while(!isnum(ch)) ch=gt();
            if(ch=='9') break;
            rot=tag=pas=0;
            while(isnum(ch)){
                if(!flg) if(s[rot][ch-'0']) pas=(id[rot=s[rot][ch-'0']]?1:0);else id[rot=s[rot][ch-'0']=++tot]=0,tag=1,s[rot][0]=s[rot][1]=0;
                ch=gt();if(!isnum(ch)) id[rot]=1;
            }
            if(!tag||pas) flg=1;
        }
        if(!flg) printf("Set %d is immediately decodable\n",i);else printf("Set %d is not immediately decodable\n",i);
    }
    return 0;
}

你可能感兴趣的:(LOJ,Trie)