Max Score: 20Given a string S and a character C, check whether the character C is occurring together in the string S.Input FormatThe first and only line of input contains a string S and character, C separated by space.Output FormatPrint "Yes" if the character C is occurring together, otherwise print "No".Constraints1 <= |S| <= 103ExampleInputsnooze oOutputYes
Question
Max Score: 20Given a string S and a character C, check whether the character C is occurring together in the string S.Input FormatThe first and only line of input contains a string S and character, C separated by space.Output FormatPrint "Yes" if the character C is occurring together, otherwise print "No".Constraints1 <= |S| <= 103ExampleInputsnooze oOutputYes
Solution
This problem is asking you to write a program that checks if a specific character appears consecutively in a given string.
Here is a step-by-step solution in Python:
- First, you need to get the input from the user. The input will be a string and a character separated by a space. You can use the
input()function to get the user input and thesplit()function to separate the string and the character.
S, C = input().split()
- Next, you need to check if the character
Cis occurring together in the stringS. You can do this by iterating over the string and checking if the current character and the next character are both equal toC.
for i in range(len(S) - 1):
if S[i] == C and S[i+1] == C:
print("Yes")
break
else:
print("No")
In this code, the for loop iterates over the string S. If the current character and the next character are both equal to C, it prints "Yes" and breaks the loop. If the loop finishes without finding any consecutive occurrences of C, it prints "No". The else clause associated with the for loop is executed when the loop has finished normally (i.e., without encountering a break statement).
Here is the complete code:
S, C = input().split()
for i in range(len(S) - 1):
if S[i] == C and S[i+1] == C:
print("Yes")
break
else:
print("No")
This code will solve the problem as described.
Similar Questions
Even SplitMax Score: 50Given a number N, check if you can split the number into 2 non-zero even parts.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a single integer N.Output FormatFor each test case, print "Yes" if you can split the number into 2 non-zero even parts, "No" otherwise, separated by new line.Constraints1 <= T <= 1050 <= N <= 1018ExampleInput285OutputYesNoExplanationExample 1:You can split 8 as 4,4 or 6,2.Example 2:You cannot split 5 into 2 even parts.
Max Score: 20Print rectangle pattern. See the example for more details.Input FormatThe first and only line of input contains a single integer N.Output FormatFor the given integer, print a rectangle pattern as shown in the example.Constraints1 <= N <= 50ExampleInput5Output5432*543*154*215*321*4321
First line of input contains T - number of test cases. Its followed by T lines, each line contains a string of size N, containing only lowercase english alphabets.Output FormatFor each test case, print the length of the largest substring that does not contain any vowel, separated by newline.Constraints1 <= T <= 1001 <= N <= 104ExampleInput3smartinterviewsalgorithms
Even SplitGiven a number N, check if you can split the number into 2 non-zero even parts.InputFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a single integer N.OutputFor each test case, print "Yes" if you can split the number into 2 non-zero even parts, "No" otherwise, separated by new line.Constraints1 <= T <= 1050 <= N <= 1018ExampleInput281OutputYesNoExplanationTest Case 1You can split 8 as 4,4 or 6,2.Test Case 2You cannot split 1 into 2 even parts.
Max Score: 100Print a hollow diamond pattern using '*'. See examples for more details.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each line contains a single odd integer N - the size of the diamond.Output FormatFor each test case, print the test case number as shown, followed by the diamond pattern, separated by a new line.Constraints1 <= T <= 1003 <= N <= 201ExampleInput437515OutputCase #1: ** * *Case #2: * * * * ** * * * * * *Case #3: * * ** * * * *Case #4: * * * * * * * * * * * * ** * * * * * * * * * * * * * *
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.