68 774
Assignments Done
98,8%
Successfully Done
In January 2019

# Answer to Question #60881 in Java | JSP | JSF for sangeetha

Question #60881
Super ASCII String Checker
In 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.

Input Format:

First line contains number of test cases T, followed by T lines, each containing
a string "S".

Output Format:

For each test case print "Yes" if the String "S" is super ascii, else print "No"
Constraints:

1<=T<=100

1<=|S|<=400, S will contains only lower case alphabets ('a'-'z').

Sample Input and Output

SNo. Input Output

1 bba Yes

2 scca No
import java.util.Scanner;

public class String_Checker {
public static void main (String[] args) {
Scanner in = new Scanner (System.in); //input stream

int T; //number of test cases
T = in.nextInt (); //reading number of test cases
String S; //cheching string
S = in.nextLine (); //moving to the next line after number

for (int t = 0; t < T; t++) {
S = in.nextLine (); //reading checking string

int[] a = new int[26]; //array for counting characters
for (int i = 0; i < 26; i++) //setting arrays values
a[i] = 0;
int n = S.length ();

for (int i = 0; i < n; i++) //counting each character in string
a[S.charAt (i) - 'a']++;

boolean is_ok = true; //value for checking string, 'is_ok' = true - string is super ascii string, othewise - string is not super ascii string

for (int i = 0; i < 26; i++) //checking loop
if (a[i] != 0 && a[i] != i + 1) { //if count of each character in the string is not equal to its ascii value
is_ok = false;
break;
}

System.out.println (is_ok ? "Yes" : "No"); //printing answer
}

}
}

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!