-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva471.cpp
More file actions
76 lines (62 loc) · 1.03 KB
/
uva471.cpp
File metadata and controls
76 lines (62 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using namespace std;
#include<iostream>
#include<vector>
#include<cstdio>
#include<queue>
#include<cstring>
#include<map>
#define di cout<<"enter"<<endl
map<string,long>m;
void bfs()
{
string temp;
queue<string>Q;
for(char i='a';i<='z';i++)
{
string Eemp;
Eemp.push_back(i);
Q.push(Eemp);
}
long cnt=1;
while(!Q.empty())
{
temp=Q.front();
Q.pop();
m[temp]=cnt;
cnt++;
if(temp=="vwxyz")
return;
for(char i=temp[temp.length()-1]+1;i<='z';i++)
{
string recent=temp+i;
Q.push(recent);
}
}
}
bool valid(string str)
{
int l=str.length();
for(int i=0;i<l-1;i++)
{
if(str[i]>=str[i+1])
return false;
}
return true;
}
int main()
{
string str;
bfs();
while(cin>>str)
{
if(valid(str))
{
printf("%ld\n",m[str]);
}
else
{
printf("0\n");
}
}
return 0;
}