Codechef Playlist problem solution

In this Codechef Playlist problem solution Chef's playlist contains 33 songs named A, BA,B, and CC, each of duration exactly XX minutes. Chef generally plays these 33 songs in loop, i.e, A \rightarrow B \rightarrow C \rightarrow A \rightarrow B \rightarrow C \rightarrow A \rightarrow \dotsA→B→C→A→B→C→A→…

Chef went on a train journey of NN minutes and played his playlist on loop for the whole journey. How many times did he listen to the song CC completely?

Codechef Playlist problem solution


Problem solution in Python.

# cook your dish here
t = int(input())
for i in range(0,t):
    arr=[int(x) for x in input().split()]
    n=arr[0]
    x=arr[1]*3
    time=int(n/x)
    print(time)



Problem solution in Java.

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
	{
		Scanner sc = new Scanner (System.in);
		int T = sc.nextInt();
		while(T > 0)
		{
		    int n = sc.nextInt();
		    int x = sc.nextInt();
		    System.out.println((n)/(3*x));
		    T--;
		    
		}
	}
}



Problem solution in C++.

#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) 
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout); 
#define ll long long 
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
        int N,X;
        cin>>N>>X;
        if(N<X){
               cout<<0<<endl;
        }
        else
        {cout<<N/(3*X)<<endl;}
}
	return 0;
}



Problem solution in C.

#include <stdio.h>

int main(void) {
	int T;
    scanf("%d",&T);
	while(T--)
	{
	    int N,X;
	    scanf("%d%d",&N,&X);
	    int k=N/X;
	    printf("%d\n",k/3);
	}
	return 0;
}


Post a Comment

0 Comments