[Solved] Daily Routine with Java, C++, Python

Daily Routine: Brendon is a little techno-whiz whose IQ is out of the charts. He has set up a laboratory at home for his research and development and was once approached by an Event Management firm to design them a Robot that would log all the activities carried out in an event at various instants during the day. This would help them keep a track and in smooth functioning of events.
Brendon, after long days of hard work designed one such Robot but wanted to test it on his own daily routines. His daily routine is very simple, he starts his day working in a computer, then he eats food and finally proceeds for sleeping thus ending his day. He has programmed his Robot to log the activities of him at various instants during the day.
Today it recorded activities that Brendon 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 Brendon was working in Computer, ‘E’ denoting he was eating and ‘S’ means he was sleeping.
Write a program to tell whether the record log made by the robot could possibly be correct or not.

Input Format:
The only line of input contains the string s.

Output Format:
Output a single line containing “yes” or “no” (without quotes) accordingly.
Refer sample input and output for formatting specifications.

Sample Input 1:
CES

Sample Output 1:
yes

Sample Input 2:
SCCC

Sample Output 2:
no

Solution

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

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
	    Scanner sc=new Scanner(System.in);
        String s=sc.next();
	    int temp=0;
	    for(int i=1;i<s.length();i++)
	    {
	        if(s.charAt(i)<s.charAt(i-1))
	        {
	            //sauravhathi
	            temp=1;
	        }
	    }
	    if(temp==1)
	    {
	        System.out.println("no");
	    }
	    else{
	        System.out.println("yes");  
	    }
	}
}
#include<bits/stdc++.h>
#include <iostream>
using namespace std;

int main() {
    long n,i;
    string s;
    cin>>s;
    n=s.length();
    int a[n];
    for(i=0;i<n;i++)
    {
        if(s[i]=='C')
        {
            a[i]=0;
        }
        else if(s[i]=='E')
        {
            a[i]=1;
        }
        else
        {
            a[i]=2;
        }
    }
    bool flag=false;
    for(i=0;i<n-1;i++)
    {
        if(a[i]<=a[i+1])
        {
            flag=true;
        }
        else
        {
            flag=false;
            break;
        }
    }
    if(flag==true)
    {
        cout<<"yes"<<endl;
    }
    else
    {
        cout<<"no"<<endl;
    }
	return 0;
}
string=input()
activities_set=set()
ans='yes'
for j in range(len(string)):
    if string[j]=='C':
        if 'E' in activities_set or 'S' in activities_set:
            ans='no'
            break
        activities_set.add('C')
    elif string[j]=='E':
        if 'S' in activities_set:
            ans='no'
            break
        activities_set.add('E')
    elif string[j]=='S':
        activities_set.add('S')
print(ans)

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

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