Strong Language CodeChef April Long Challenge Solution| AskTheCode

Updated: Apr 12

CodeChef April Long Challenge2021 Solution | Strong Language (SSCRIPT) solution in C++ | ATC

Problem:

A string is said to be using strong language if it contains at least K consecutive characters '*'.

You are given a string S with length N. Determine whether it uses strong language or not.

Input:

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.

  • The first line of each test case contains two space-separated integers N and K.

  • The second line contains a single string S with length N.

Output:

Print a single line containing the string "YES" if the string contains strong language or "NO" if it does not (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Example Input:

3 5 2 *a*b* 5 2 *a**b 5 1 abcde

Example Output:

NO YES NO

Explanation:

Example case 1: Since there are no two consecutive characters '*', the string does not contain strong language.

Example case 2: There are two adjacent characters '*', so the string contains strong language.

Example case 3: Since there are no characters '*' in the string, it does not contain strong language.

Code:

In C++

#include <iostream>
using namespace std;

int main() {
	int t;
	char pre='*';
	cin>>t;
	while(t--)
	{
	    string s;
	    int l,h,count=0;
	    cin>>l>>h;
	    cin>>s;
	    for(int i=0;i<l;i++)
	    {
	        if(pre==s[i])
	        {
	            count++;
	            if(count==h)
	            {
	                cout<<"yes"<<endl;
	              break;
	            }
	        }
	        else
	        {
	            count=0;
	           
	        }
	      
	    }
	    if(count!=h)
	   cout<<"no"<<endl;  
	}
	 
	return 0;
}

In Python

test = input()

for i in range(test):
    nk = map(int,raw_input().split())
    n = nk[0]
    k = nk[1]
    script = raw_input()
    substring = k*"*"
    present = ""
    answer = []

    for i in range(n) :
        if(script[i] == "*"):
            present = present + "*"
        if(present == substring):
            print("YES")
            break
        if(script[i] != "*"):
            present = ""
        if(i == n-1):
            print("NO")
1,181 views0 comments

Recent Posts

See All

Solubility - CodeChef Solution in Java and C++| AskTheCode

CodeChef May Long Challenge Solution | Solubility (SOLBLTY) solution | AskTheCode Solubility (SOLBLTY) solution Problem: Suppose for a unit rise in temperature, the solubility of sugar in water increa

Valid Paths CodeChef Solution in C++ | AskTheCode

CodeChef May Long Challenge Solution | Valid Paths (VPATH) solution | AskTheCode Valid Paths (VPATH) CodeChef solution Problem: You are given a tree with N nodes numbered from 1 to N. A set S of nodes