Super Ascii - Code Vita 2014 | round 2

Super Ascii


Problem Decription:

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.InputOutput
1
2
bba
scca

Yes
No



Program:

#include <stdio.h>
int main() {
    char s[30];
    int i,num[30]={0},isascii,n;
    scanf("%d",&n);
    while(n--)
    {
    scanf("%s",s);
    i=0;
    isascii=1;
    while(s[i]!='\0')
    {
        if((s[i]>='a')&&(s[i]<='z'))
        num[s[i]-'a']++;
        s[i]='\0';
        i++;
    }
    for(i=0;i<26;i++)
    {
        if((num[i]>0)&&(num[i]!=(i+1)))
        isascii=0;
        num[i]=0;
    }
    if(isascii)
    printf("yes\n");
    else
    printf("no");
    }
    return 0;
}

Output:

2
bba
scca

yes
no

You can also run it on the online IDE: https://ide.geeksforgeeks.org/q64aeIcLxM

Your feedback and comments are welcomed! If you have an doubt can contact me or comment below! Cheers!

Related Link: Date Time 2018

4 comments:

  1. package Tcs;

    import java.util.Scanner;

    public class SuperAscii {
    public static String check(String s)
    {
    String ans="Yes";
    int count[]=new int[256];
    for(int i=0;i0)
    {
    String s=sc.next()+sc.nextLine();
    String ans=check(s);
    sb.append(ans+"\n");
    }
    System.out.print(sb);
    }

    }

    ReplyDelete
  2. Send a code in python language

    ReplyDelete
  3. #include
    #include
    int main()
    {
    char a[100],temp=0,p=0;
    int i,j,c=1,r,k=0,x[100],s;
    // printf("the ascii of a is 097\n");
    // printf("enter the string :");
    scanf("%s",&a);
    s=strlen(a);
    for(i=0;i<s;i++)
    { c=1;
    for(j=i+1;j<s;j++)
    {
    if(a[i]==a[j] && p!=a[i])
    { temp=a[i];
    // printf("%c",a[i]);
    c++;
    r=a[i]-96;
    }
    }
    p=temp;
    if(c==1)
    {
    r=a[i]-96;
    }
    if(r==c)
    {
    k=k+c;
    // printf("%d\t",c);
    }
    }
    // printf("%d",k);
    if(s==k)
    {
    printf("\tsuper ");
    }
    main();
    }

    ReplyDelete

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...