Problem link:417(Word index)
Solution code:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<list>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
map<string,int>my;
void pre_generate()
{
int total=1;
for(int i=0;i<5;i++)
{
string c;
for(int j=1;j<=26;j++)
{
c=c+char(j+96);
if(i==0)
{
my[c]=total++;
}
else for(int l=j+1;l<=26;l++)
{
c=c+char(l+96);
if(i==1)
{
my[c]=total++;
}
else
for(int m=l+1;m<=26;m++)
{
c=c+char(m+96);
if(i==2)
{
my[c]=total++;
}
else
{
for(int n=m+1;n<=26;n++)
{
c=c+char(n+96);
if(i==3)
{
my[c]=total++;
}
else
{
for(int o=n+1;o<=26;o++)
{
c=c+char(o+96);
my[c]=total++;
c.erase(4,c.size());
}
}
c.erase(3,c.size());
}
}
c.erase(2,c.size());
}
c.erase(1,c.size());
}
c.erase(0,c.size());
}
}
}
int main()
{
//freopen("c:\\temp\\in.txt","r",stdin);
pre_generate();
string input;
while(cin>>input)
{
cout<<my[input]<<endl;
}
}
0 comments:
একটি মন্তব্য পোস্ট করুন