#include<cstdio> #include<cstring> #include<string> #include<iostream> #include<map> #include<algorithm> using namespace std; int main() { //freopen("output.txt","w",stdout); int i,j,k,l=1,m=26,n=0,find=83681; string s,t; map<string, int>cha; string ch[84000]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; string c[26]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; for(i=0;i<26;i++) { cha[ch[i]]=i+1; } l=0; for(l=0;m!=83681;l++) { s=ch[l]; for(i=0;i<26;i++) { t=s; t=t+c[i]; int f=0; for(k=0;k<t.length()-1;k++) { if(t[k]>=t[k+1])f=1; } if(f==0){ cha[t]=m; ch[m++]=t; } if(m==83681)break; } } while(cin >> s) { if(s=="a")cout << "1\n"; else if(s.length()==1)cout << cha[s]<<endl; else if(cha[s]==0)cout << "0\n"; else cout << cha[s]+1<<endl; } return 0; }
Sunday, August 17, 2014
uva : 417 - Word Index
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment