forked from rmkcodingclub/solutions2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperAscii.cpp
28 lines (28 loc) · 865 Bytes
/
superAscii.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
#include <iostream>
#include <string>
using namespace std;
int main()
{
int testCases;
cin >> testCases;
while ( testCases-- > 0) {
string inputString;
cin >> inputString;
int alphaCount['z' - 'a' + 1] = {}; // an array with the number of occurrences of each letter
for (int i = 0; i < inputString.length(); ++i) { // calculate the number od occurreces of each letter
++alphaCount[inputString[i] - 'a']; // S[i] - 'a' is the ascii code of the letter S[i]
}
bool flag = true;
for (int i = 0; i <= 'z' - 'a'; ++i) {
if (alphaCount[i] != i + 1 && alphaCount[i] > 0){
flag = false; // the array is indexed from 0 but the ascii codes are starting from 1, so we check for cnt[i] != i + 1
}
}
if ( flag == true){
cout << "Yes";
}
else {
cout << "No";
}
}
}