Problem Type: map (Java TreeMap)
Problem Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=358&mosmsg=Submission+received+with+ID+20216008
Source code :
/***
Tarequzzaman Khan
CSE'12
2012331514
*/
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int>mp;
void load()
{
queue<string> q;
string s = "";
int cou =1;
for(int i=97; i<=122; i++)
{
char c = i;
s+=c;
mp[s]=cou;
q.push(s);
cou ++;
s="";
}
while(!q.empty())
{
string s = q.front();
q.pop();
for(int i=97; i<=122; i++)
{
char c = i;
int len = s.length();
if(s[len-1]<c)
{
string m = s+c;
if(m.length()>5)
break;
mp[m]=cou;
q.push(m);
cou ++;
}
}
}
}
int main()
{
/***
Tarequzzaman Khan
CSE'12
2012331514
*/
load();
string s ;
while(cin >>s)
{
cout << mp[s] << endl;
}
}
No comments:
Post a Comment