Chef and his daily routine Codechef Solution

Chef and his daily routine Codechef Solution: Chef’s daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at various instants during the day. Today it recorded activities that Chef was doing at N different instants. These instances are recorded in chronological order (in increasing order of time). This log is provided to you in form of a string s of length N, consisting of characters ‘C’, ‘E’ and ‘S’. If s[i] = ‘C’, then it means that at the i-th instant Chef was cooking, ‘E’ denoting he was eating and ‘S’ means he was sleeping.

You have to tell whether the record log made by the robot could possibly be correct or not.

Input

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

The only line of each test case contains string s.

Output

For each test case, output a single line containing “yes” or “no” (without quotes) accordingly.

Constraints

  • 1 ≤ T ≤ 20
  • 1 ≤ N ≤ 105

Subtasks

  • Subtask #1 (40 points) : 1 ≤ N ≤ 100
  • Subtask #2 (60 points) : original constraints

Sample Input 1 

5
CES
CS
CCC
SC
ECCC

Sample Output 1 

yes
yes
yes
no
no

Explanation

Example case 1. “CES” can correspond to a possible record of activities of Chef. He starts the day with cooking, then eating and then sleeping.

Example case 2. “CS” can also correspond to a possible record of activities of Chef. He starts the day with cooking, then eating and then sleeping. Robot recorded his cooking and sleeping in order. He might not have recorded his eating activity.

Example case 4. “SC” can not correspond to Chef’s activities. Here it means that Chef slept first, then he cooked the food, which is impossible for Chef to do on some particular day

Chef and his daily routine- CodeChef Solution in JAVA

import java.util.*;
import java.io.*;
public class Main {
 public static int to(char ch){
 	int tore=0;
		if(ch=='C')
		 tore=0;
		else if(ch=='E')
		 tore=1;
		else if(ch=='S')
		 tore=2;
	return tore;
	}
	public static void main(String[] args) {
try{
    Scanner sc=new Scanner(System.in);
     int t=sc.nextInt();
    while(t-->0){
       String s=sc.next();
       boolean flag=true;
      for(int i=1;i<s.length();i++){
       if(to(s.charAt(i))<to(s.charAt(i-1))){
         flag=false;
         break;
       }
      }
     if(flag)
      System.out.println("yes");
     else
      System.out.println("no");
	}
	}catch(Exception e){return;}
	}
}

Chef and his daily routine  – CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--)
    {
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='C')
        {
            if(s[i+1]=='E'||s[i+1]=='S'||s[i+1]=='C')
            count++;
        }
        if(s[i]=='E')
        {
            if(s[i+1]=='S'||s[i+1]=='E')
            count++;
        }
        if(s[i]=='S')
        {
            if(s[i+1]=='S')
            count++;
        }
    }
    if(count==s.size()-1)
    cout<<"yes"<<endl;
    else
    cout<<"no"<<endl;
    }
	// your code goes here
	return 0;
}

Chef and his daily routine -CodeChef Solution in Python

t = int(input())
for i in range(t):
    s = input()
    n = len(s)
    k = 0
    for j in range(n - 1):
        if s[j] > s[j + 1]:
            k = 1
            break
    print('no' if k == 1 else 'yes')

Disclaimer: The above Problem(Chef and his daily routine) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment