/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100000 map<string, int> mp; int cnt; void precal(string s, int len) { if(s.length()==len) { mp[s]=cnt++; return; } //cout<<s<<endl; char lst; if(s.length()==0) lst='a'; else lst = s[s.length()-1]+1; for(char ch=lst;ch<='z';ch++) precal(s+ch, len); return; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int tc, kk=1, n; string s; cnt=1; for(int i=1;i<=5;i++) { precal("", i); // cout<<i<<endl; } while(cin>>s) { cout<<mp[s]<<"\n"; } return 0; }
Wednesday, 2 March 2016
Word Index (UVA 417, UVALive 5392, ZOJ 1342, POJ 1496, HDU 1336, SCU 1024)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment