Sunday, June 04, 2017

Solution - UVa 417

Image result for Uva online

UVa online judge

problem:417

word index

problem: 

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=358

 

soluton:

#include<bits/stdc++.h>
using namespace std;
map<string, int>mp;
void index()
{
    int cnt=0;
    string b,a="abcdefghijklmnopqrstuvwxyz";
    for(int i=0; i<26; i++)
    {
        cnt++;
        b="";
        b+=a[i];
        mp[b]=cnt;
    }
    for(int i=0; i<26; i++)
        for(int j=i+1; j<26; j++)
        {
            cnt++;
            b="";
            b+=a[i];
            b+=a[j];
            mp[b]=cnt;
        }
    for(int i=0; i<26; i++)
        for(int j=i+1; j<26; j++)
            for(int k=j+1; k<26; k++)
            {
                cnt++;
                b="";
                b+=a[i];
                b+=a[j];
                b+=a[k];
                mp[b]=cnt;
            }

    for(int i=0; i<26; i++)
        for(int j=i+1; j<26; j++)
            for(int k=j+1; k<26; k++)
                for(int l=k+1; l<26; l++)
                {
                    cnt++;
                    b="";
                    b+=a[i];
                    b+=a[j];
                    b+=a[k];
                    b+=a[l];
                    mp[b]=cnt;
                }

    for(int i=0; i<26; i++)
        for(int j=i+1; j<26; j++)
            for(int k=j+1; k<26; k++)
                for(int l=k+1; l<26; l++)
                    for(int m=l+1; m<26; m++)
                    {
                        cnt++;
                        b="";
                        b+=a[i];
                        b+=a[j];
                        b+=a[k];
                        b+=a[l];
                        b+=a[m];
                        mp[b]=cnt;
                    }

}
int main()
{
    ios::sync_with_stdio(false);
    index();
    string c;
    while(cin>>c)
        cout<<mp[c]<<endl;

    return 0;
}

//Language:C++


2 comments: