Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss417 - | Accepted | C++11 | 0.060 | 0.000 | 4155 | 2 mins ago |
Problem: http://uva.onlinejudge.org/external/4/417.pdf
Suggest:
- Since the maximum number of characters is 5, we can use 5 for loops to represent it (similar to 1 2 3 4) and save it to a map<string, int> to output the result.
#include<bits/stdc++.h>
using namespace std;
int cnt;
unordered_map<string, int> F;
string s;
int main(){
for(int i='a'; i<='z'; i++){
s="";
s+=char(i);
++cnt;
F[s] = cnt;
}
for(int i='a'; i<='z'; i++)
for(int j=i+1; j<='z'; j++)
if (j <= 'z')
{
s="";
s=s + char(i) + char(j);
++cnt;
F[s] = cnt;
}
for(int i='a'; i<='z'; i++)
for(int j=i+1; j<='z'; j++)
for(int k=j+1; k<='z'; k++)
if (k <= 'z')
{
s="";
s=s + char(i) + char(j) + char(k);
++cnt;
F[s] = cnt;
}
for(int i='a'; i<='z'; i++)
for(int j=i+1; j<='z'; j++)
for(int k=j+1; k<='z'; k++)
for(int l=k+1; l<='z'; l++)
if (l <= 'z')
{
s="";
s=s + char(i) + char(j) + char(k) + char(l);
++cnt;
F[s] = cnt;
}
for(int i='a'; i<='z'; i++)
for(int j=i+1; j<='z'; j++)
for(int k=j+1; k<='z'; k++)
for(int l=k+1; l<='z'; l++)
for(int m=l+1; m<='z'; m++)
if (m <= 'z')
{
s="";
s=s + char(i) + char(j) + char(k) + char(l) + char(m);
++cnt;
F[s] = cnt;
}
ios::sync_with_stdio(false); cin.tie(nullptr);
while(cin >> s){
cout<<F[s]<<"\n";
}
}
No comments:
Post a Comment