Question of the day - Sunny or Rainy - 12/03/2023
Sunny or Rainy?
Time Limit: 2 sec
Memory Limit: 128000 kB
Memory Limit: 128000 kB
Problem Statement
You are given a string S, which represents a weather forecast for the seven days starting tomorrow.
The ith of those seven days is forecast to be sunny if the ith character of S is o, and rainy if that character is x. Tell us whether the Nth day is forecast to be sunny.
The ith of those seven days is forecast to be sunny if the ith character of S is o, and rainy if that character is x. Tell us whether the Nth day is forecast to be sunny.
Input
The first line of the input consists of an integer N.
The second line of the input consists of a string.
Constraints
N is an integer between 1 and 7 (inclusive).
S is a string of length 7 consisting of o and x.
The second line of the input consists of a string.
Constraints
N is an integer between 1 and 7 (inclusive).
S is a string of length 7 consisting of o and x.
Output
Print Yes if the N- th of the seven days starting tomorrow is forecast to be sunny, and No if that day is forecast to be rainy.
Solution:-
see the blow solution for above problem. I have tried my best to provide the solution of this problem you can check this as well.
Java:-
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String str=sc.next();
if(str.charAt(n-1) == 'o'){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
JavaScript:-
const args = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split(/\s+/);
const num = parseInt(args[0]);
const forecast = args[1];
console.log(forecast[num - 1] == 'o' ? 'Yes' : 'No');
C++:-
#include<stdio.h>
int main(){
int n;
char s[8];
scanf("%d %s",&n,s);
if(s[n-1]=='o')puts("Yes");
else puts("No");
}
Python:-
N=int(input())
S=input()
if S[N-1]=="o": print('Yes')
else: print('No')
If you liked this article, share it with your friends and colleagues!
No comments: