Correct Sentence CodeChef Solution

Problem -Correct Sentence CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Correct Sentence CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin >>t;
	while(t--){
	    int k;
		cin >>k;
		bool ans  = true;

	    while(k--){
	        string str;
	        cin >>str;
	        int l = str.length();
			bool lower =false;
			bool upper =false;
	        for(int i=0;i<l;i++){

				int integer;
				integer = str[i];
				if(integer>=97 && integer<=109){
					lower  = true;
				}else{
					if(integer>=78 && integer<=90){
						upper  = true;
					}else{
						ans  = false;
					}
				}
				if(upper && lower ){
					ans  = false;
				}
	        }
			
	}
	if(ans){
				cout << "YES"<<endl;
		
			}else{
				cout << "NO"<<endl;
			}
	
}
return 0;
}

Correct Sentence CodeChef Solution in C++14

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

template <typename T>
void get_input(T& A) {
    for_each(A.begin(), A.end(), [](auto& x) {cin >> x; });
}

bool is_lang_1(string const& s) {
    for (auto const& c : s) {
        if (!(c >= 'a' && c <= 'm'))
            return false;
    }

    return true;
}

bool is_lang_2(string const& s) {
    for (auto const& c : s) {
        if (!(c >= 'N' && c <= 'Z'))
            return false;
    }

    return true;
}
bool is_chef_lang(vector<string> const& A) {
    for (auto const& a : A) {
        if (!is_lang_1(a) && !is_lang_2(a))
            return false;
    }

    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T{ 0 };
    cin >> T;

    while (T--) {
        int K{ 0 };
        cin >> K;
        vector<string> A(K);
        get_input(A);

        bool result{ is_chef_lang(A)};
        cout << (result ? "YES" : "NO") << endl;
    }
}

Correct Sentence CodeChef Solution in PYTH 3

import sys
input = sys.stdin.readline
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
def outp(n):
    sys.stdout.write(str(n) + "\n")
def outlt(lst):
    # outputs lst elements on a sigle line
    sys.stdout.write(" ".join(map(str,lst)) + "\n")
def outplt(lst):
    # outputs lst elements on seperate lines
    sys.stdout.write("\n".join(map(str,lst)))
def outpltlt(lst):
    # outputs lst of lst elements seperateed by space on seperate lines
    sys.stdout.write("\n".join(map(str,(" ".join(map(str, a)) for a in lst))))
 
# ----------------------------------------------
ans = []

for _ in range(inp()):
    an = 'NO'
    for s in input().split()[1:]:
        if not ((s.islower() and max(s) <= 'm') or (s.isupper() and min(s) >= 'N')): break
    else:
        an = 'YES'
    ans.append(an)
outplt(ans)

Correct Sentence CodeChef Solution in C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

char str[15][110] ;

bool if_small ( int j ) {
    int i=0 ;
    while ( str[j][i] ) {
        if ( str[j][i] > 109 || str[j][i] < 97 ) return 0 ;
        i++ ;
    }
    return 1 ;
}

bool if_large ( int j ) {
    int i=0 ;
    while ( str[j][i] ) {
        if ( str[j][i] > 90 || str[j][i] < 78 ) return 0 ;
        i++ ;
    }
    return 1 ;
}

int main (void) {
    int testcases ; 
    scanf("%d", &testcases) ; 
    int i, res[testcases], n, j ;

    for ( i=0 ; i<testcases ; ++i ) {
        getchar () ;
        scanf("%d", &n) ;
        
        _Bool flag=1 , flag_ary[n] ;

        for ( j=0 ; j<n ; ++j ) {
             getchar () ;
             scanf("%s", str[j]) ;
        }

        for ( j=0 ; j<n ; ++j ) {
            if ( str[j][0]<= 109 && str[j][0]>= 97 ) flag_ary[j] = if_small( j ) ;
            else if ( str[j][0]<= 90 && str[j][0]>= 78 ) flag_ary[j] = if_large( j ) ;
            else flag_ary[j] = 0 ;
        }
         
        for ( j=0 ; j<n ; ++j ) flag *= flag_ary[j] ;
        res[i] = flag ;
    }

    for ( i=0 ; i<testcases ; ++i ) {
        if ( res[i] ) printf("YES\n");
        else printf("NO\n");
    }
}

Correct Sentence CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
		int tt=Integer.parseInt(reader.readLine().trim());
		test:
		while(tt-->0){
		    String[] parts=reader.readLine().split("\\s+");
		    for(int i=1;i<parts.length;i++){
		        if(!isValid(parts[i].trim())){
		            writer.write("NO\n");
		            continue test;
		        }
		    }
		    writer.write("YES\n");
		}
		writer.flush();
	}
	
	private static boolean isValid(String word){
	    boolean lan1=true, lan2=true;
	    for(char c: word.toCharArray()){
	        if(lan1 && (c<'a' || c>'m')){
	            lan1=false;
	        }
	        if(lan2 && (c<'N' || c>'Z')){
	            lan2=false;
	        }
	    }
	    return lan1 || lan2;
	}
	
    
    private static int[] parseInt(String str) {
        String[] parts=str.split("\\s+");
        int[] ans=new int[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Integer.parseInt(parts[i]);
        }
        return ans;
    }

    private static long[] parseLong(String str) {
        String[] parts=str.split("\\s+");
        long[] ans=new long[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Long.parseLong(parts[i]);
        }
        return ans;
    }
}

Correct Sentence CodeChef Solution in PYPY 3

for _ in range(int(input())):
    l = [x for x in input().split()]
    lang1 = "abcdefghijklm"
    lang2 = "NOPQRSTUVWXYZ"
    flag = 1
    t = 0
    for i in range(1,int(l[0])+1):
        if l[i][0] in lang1:
            for j in range(len(l[i])):
                if l[i][j] not in lang1:
                    print("no")
                    t = 1
                    flag = 0
                    break
            if t :
                break
        elif l[i][0] in lang2:
            for j in range(len(l[i])):
                if l[i][j] not in lang2:
                    print("no")
                    t = 1 
                    flag = 0
                    break 
            if t :
                break
        else:
            flag = 0 
            print("no")
            break
    if flag:
        print("yes")
        

Correct Sentence CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	st = raw_input().split()
	K = int(st[0])
	valid = True
	for k in range(1,K+1):
		if valid:
			s = st[k]
			tot = 0
			cnt = 0
			for x in s:
				cnt += 1
				n = ord(x)
				if (n > 77) and (n < 110):
					if n < 95:
						tot += 1
					else:
						tot += 2
					# endif
				else:
					tot += 300
				# endif
			# endfor x
			if not((tot == cnt) or (tot == 2*cnt)):
				valid = False
			# endif
		# endif
	# endfor k
	if valid:
		print 'YES'
	else:
		print 'NO'
	# endif
# endfor i

Correct Sentence CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Text;

namespace CORTSENT
{
    class Program
    {
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            int smallA = (int)'a';
            int smallM = (int)'m';
            int bigN = (int)'N';
            int bigZ = (int)'Z';
            List<string> K = new List<string>();

            for (int i = 0; i < T; i++)
            {
                K.Add(Console.ReadLine());
            }

            for (int i = 0; i < T; i++)
            {
                string[] words = K[i].Split(' ');
                int wordCount = int.Parse(words[0]);
                bool failFlag = false;
                for (int j = 1; j <= wordCount; j++)
                {
                    int smallCounter = 0;
                    int bigCounter = 0;
                    foreach (char ch in words[j])
                    {
                        if ((int)ch >= smallA && (int)ch <= smallM)
                        {
                            smallCounter++;
                        }
                        else if ((int)ch >= bigN && (int)ch <= bigZ)
                        {
                            bigCounter++;
                        }
                        else
                        {
                            failFlag = true;
                            break;
                        }
                    }
                    if (failFlag || (bigCounter == 0 && 0 == smallCounter)
                        || (bigCounter > 0 && smallCounter > 0))
                    {
                        failFlag = true;
                        break;
                    }
                }
                if (failFlag)
                {
                    Console.WriteLine("NO");
                }
                else
                {
                    Console.WriteLine("YES");
                }

            }
            //Console.ReadLine();
        }
    }
}

Correct Sentence CodeChef Solution in GO

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')

		for i := 0; i < len(s); i++ {
			if s[i] == ' ' {
				s = s[i+1:]
				break
			}
		}

		res := solve(s)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(sent string) bool {
	var n int
	for n < len(sent) && sent[n] != '\n' {
		n++
	}

	ss := strings.Split(sent[:n], " ")

	for _, s := range ss {
		if len(s) == 0 {
			continue
		}
		if s[0] >= 'a' && s[0] <= 'z' {
			for i := 0; i < len(s); i++ {
				if s[i] < 'a' || s[i] > 'm' {
					return false
				}
			}
		} else if s[0] >= 'A' && s[0] <= 'Z' {
			for i := 0; i < len(s); i++ {
				if s[i] < 'N' || s[i] > 'Z' {
					return false
				}
			}
		} else {
			return false
		}
	}

	return true
}
Correct Sentence CodeChef Solution Review:

In our experience, we suggest you solve this Correct Sentence CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Correct Sentence CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Correct Sentence CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *