62 558
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #44935 in C++ for sasikala

Question #44935
to find out whether the string is super ascii or not
Expert's answer
//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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions