Pastebin
API
tools
faq
paste
Login
Sign up
SHARE
TWEET
lightoj - 1129 - Consistency Checker
jakaria_hossain
Jan 17th, 2020
105
Never
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!
C++
1.14 KB
raw
download
clone
embed
print
report
RAW Paste Data
#include<bits/stdc++.h> using namespace std; //typedef long long ll; int last=1; struct node { int next[10]; bool endmark; }liist[200005]; void build(int cur) { for(int i=0;i<10;i++)liist[cur].next[i]=-1; liist[cur].endmark=false; } bool inseert(const string& s) { int cur=0,l; l=s.length(); for(int i=0;i<l;i++) { int x=s[i]-48; if(liist[cur].next[x]==-1) { build(last); liist[cur].next[x]=last++; } cur=liist[cur].next[x]; if(liist[cur].endmark)return true; } for(int i=0;i<10;i++)if(liist[cur].next[i]!=-1)return true; liist[cur].endmark=true; return false; } int main() { int test,t=1; scanf("%d",&test); while(test--) { bool res=false; int n; last =1; scanf("%d",&n); build(0); while(n--) { string s; cin>>s; if(!res)res = inseert(s); } if(res)printf("Case %d: NO\n",t); else printf("Case %d: YES\n",t); t++; } return 0; }
Public Pastes
Untitled
C | 8 min ago
Super Filter 8.0
PHP | 16 min ago
drupal - Price Res...
PHP | 24 min ago
teabase64
JSON | 24 min ago
drupal - formatter
PHP | 25 min ago
Untitled-1
C | 25 min ago
getMacAddr.sh
Bash | 32 min ago
systemd commands
Bash | 35 min ago
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!