×

Author: Praveen Dhinwa
Tester: Misha Chorniy
Editorialist: Animesh Fatehpuria

# PROBLEM

You just received a message given by a string $s$. You don't know whether this message is sent by Chef or his brother. Also, the communication channel through which you received the message is erroneous and hence can flip a letter from uppercase to lowercase or vice versa. However, you know that this channel can make at most $k$ such flips.

Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters. Determine whether the message could have been sent only by Chef, only by the little brother, by both or by none.

# EXPLANATION

Number of uppercase letters <= $k$ implies that it could have been Chef. This is because we can consider all the uppercase letters as "flips" made by the communication channel, which would imply that our original message comprised only of lowercase letters. Similarly, number of lowercase letters <= $k$ implies that it could have been Chef's brother. Here is the implementation in Python:

t = int(input()) for _ in range(t): (n, k) = list(map(int, input().split(' '))) s = input() chef = sum([1 for ch in s if ch >= 'A' and ch <= 'Z']) <= k brother = sum([1 for ch in s if ch >= 'a' and ch <= 'z']) <= k if (chef and brother): print("both") elif (chef): print("chef") elif (brother): print("brother") else: print("none")

# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

This question is marked "community wiki".

8731420
accept rate: 9%

19.0k348495533

 0 I need help with my code. LINK: https://ideone.com/e33lVw answered 10 Jan, 19:45 2★akkiei 11●1 accept rate: 0% In the main fucntion, look at these lines: char arr[n]; cin>>arr;  Issues: You shouldn't declare static allocation inside the main function. These allocations will be done in stack space and with each test case the allocation will be done again. An alternate nice way of doing the same is to either do a dynamic memory allocation or declare "char arr[105]" globally. Note that the size of array is taken 105 which is greater than largest value of $N$. Use scanf for reading a string. If you want to use cin, you can do with string class in C++. int main() { string s; cin >> s; } (11 Jan, 09:09) admin ♦♦0★
 0 Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters. You just received a message given by a string s. You don't know whether this message is sent by Chef or his brother. Also, the communication channel through which you received the message is erroneous and hence can flip a letter from uppercase to lowercase or vice versa. However, you know that this channel can make at most K such flips. Determine whether the message could have been sent only by Chef, only by the little brother, by both or by none. answered 16 Jan, 10:41 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,434
×75
×14
×6

question asked: 16 Dec '17, 11:35

question was seen: 971 times

last updated: 20 Feb, 16:43