# Answer to Question #53866 in C++ for rethna

Question #53866

n the Byteland country a string "S" is said to super ascii string if and only if count of each character in the string is equal to its ascii value.

In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.

Your task is to find out whether the given string is a super ascii string or not.

In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.

Your task is to find out whether the given string is a super ascii string or not.

Expert's answer

Solve

#include <iostream>

int main()

{

char str[100];

std::cout<<"Input string: ";

std::cin>>str;

int i=0;

//calculate number of symbols:

int numbers[26]={0};

while(str[i]!='\0')

{

if((str[i]>='a')&&(str[i]<='z'))

numbers[str[i]-'a']++;

i++;

}

//check numbers and number in super ascii:

int isAscii=1;

for(i=0;i<26;i++)

if((numbers[i]>0)&&

(numbers[i]!=(i+1)))

{

isAscii=0;

break;

}

if(isAscii==0)

std::cout<<"No";

else

std::cout<<"Yes";

return 0;

}

#include <iostream>

int main()

{

char str[100];

std::cout<<"Input string: ";

std::cin>>str;

int i=0;

//calculate number of symbols:

int numbers[26]={0};

while(str[i]!='\0')

{

if((str[i]>='a')&&(str[i]<='z'))

numbers[str[i]-'a']++;

i++;

}

//check numbers and number in super ascii:

int isAscii=1;

for(i=0;i<26;i++)

if((numbers[i]>0)&&

(numbers[i]!=(i+1)))

{

isAscii=0;

break;

}

if(isAscii==0)

std::cout<<"No";

else

std::cout<<"Yes";

return 0;

}

## Comments

## Leave a comment