-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Alphabetical_Strings.cpp
64 lines (56 loc) · 1.13 KB
/
B_Alphabetical_Strings.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// int gcd(int a, int b) {
// if (a == 0 || b == 0)
// return 0;
// else if (a == b)
// return a;
// else if (a > b)
// return gcd(a-b, b);
// else return gcd(a, b-a);
int main()
{
ll t;
cin >> t;
while (t--)
{
ll z = 1001;
string str;
cin >> str;
int n = str.length();
char ch = 'a';
ch = ch + n - 1;
int a=1;
int b=a;
int m = n;
int final = 1;
while (n > 0)
{
if (str[0] == ch)
{
str.erase(0, 1);
ch--;
m--;
}
else if (str[m - 1] == ch)
{
str.erase(m - 1, m - 1);
ch--;
m--;
}
else
{
cout << "NO" << endl;
final = 0;
break;
}
n--;
}
int x=a;
if (final && str.length() == 0)
{
cout << "YES" << endl;
}
}
}