//Answer on Question#44935 - Progamming - C++#include <iostream>#include <string>using namespace std;bool is_super(string s) { int cnt['z' - 'a' + 1] = {}; // an array with the number of occurrences of each letter for (int i = 0; i < s.length(); ++i) { // calculate the number od occurreces of each letter ++cnt[s[i] - 'a']; // s[i] - 'a' is the code of the letter s[i] } bool res = true; for (int i = 0; i <= 'z' - 'a'; ++i) { if (cnt[i] != i + 1 && cnt[i] > 0) res = false; // the array is indexed from 0 but the codes are starting from 1, so we check for cnt[i] != i + 1 } return res;}int main() { string s; cin >> s; if (is_super(s) == true) cout << "Is super ASCII" << endl; else cout << "Isn't super ASCII" << endl;}
Comments