click below for solution

Sunday, 23 January 2022

Palidromes Not allowed Solution |


It is JJ's birthday and you decide to gift him a string S (consisting of English alphabet only) of length N. But you also know that JJ does not like palindromes so you decide that none of the substrings of S of length ≥2 should be a palindrome.


Can you find any suitable string which can be gifted to JJ?


Recall that a string is called palindrome if it reads the same backwards and forwards, for e.g. noon and level are palindromic strings.


Input Format

The first line contains T - the number of test cases. Then the test cases follow.

The first and only line of each test case contains an integer N - the length of the string S to be constructed.

Output Format

For each test case, output a string S of length N such that none of its substrings (of length ≥2) is a palindrome.


If there are multiple strings which satisfy the condition, print any.


Constraints

1≤T≤100

1≤N≤1000

Sample Input 1 

3

2

2

4

Sample Output 1 

gl

hf

waow

Explanation

Test case 1: gl is the only substring of length ≥2 and it is not a palindrome.


Test case 2: hf is the only substring of length ≥2 and it is not a palindrome.


Test case 3: Following are the substrings of length ≥2:


Length=2: wa, ao, ow

Length=3: wao, aow

Length=4: waow

We can see that none of these substrings is a palindrome

Solution

<b>#include <bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    string s1 = "abcdefghijklmnopqrstuvwxyz";

    while (t--)

    {

        string s = "";

        int l = 0;

        cin >> l;

        int i = 0;

        while (l--)

        {

            s += s1[i];

            if (i == 25)

            {

                i = 0;

            }

            i++;

        }

        cout << s <<endl;

    }

    return 0;

}</b>


Mask Policy solution|Codesheff January contest cook off 2022

In a survey, it was found that A out of the N people living in the city are currently infected. It has been observed that the only way for a person to get infected is if he comes in contact with an already infected person, and both of them are NOT wearing a mask.

The mayor of the city wants to make a new Mask Policy and find out the minimum number of people that will be required to wear a mask to avoid the further spread of the virus. Help the mayor in finding this number.

Note: The only aim of the mayor is to stop virus spread, not to mask every infected person.

Input Format

  • The first line contains T - number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two integers N and A - the total number of people living in the city and the number of people already affected by the virus respectively.

Output Format

For each test case, output the minimum number of people that will be required to wear a mask so as to curb the virus spread.

Constraints

  • 1T105
  • 2N400
  • 1A<N

Sample Input 1 

3
2 1
3 2
3 1

Sample Output 1 

1
1
1

Explanation

Test Case #1: There is 1 infected person and 1 uninfected person. We can ask any of them to wear a mask, and no more infections will occur. Hence the answer is 1.

Test Case #2: There are 2 infected people and 1 uninfected person. We can ask the uninfected person to wear a mask, and no more infections will occur. Hence the answer is 1.

Test Case #3: There is 1 infected person and 2 uninfected people. We can ask the single infected person to wear a mask, and no more infections will occur. Hence the answer is 1.

Solution











Hungry Ashish Solution| January Cook-off 2022 Division 3 solution

Ashish can eat at most one thing. Find out what will Ashish eat for his dinner.

Input Format

  • The first line will contain T - the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains three integers XY and Z - the money Ashish has, the cost of a PIZZA and the cost of a BURGER.

Output Format

For each test case, output what Ashish will eat. (PIZZABURGER or NOTHING).

You may print each character of the string in uppercase or lowercase. (for example, the strings PizzapIzZa and piZZa will all be treated as identical).

Constraints

  • 1T100
  • 1X,Y,Z100

Sample Input 1 

3
50 40 60
40 55 39
30 42 37

Sample Output 1 

PIZZA
BURGER
NOTHING

Explanation

Test case-1: Ashish has 50 rupees while the cost of PIZZA is 40. Therefore he can buy a PIZZA for his dinner.

Test case-2: Ashish has 40 rupees. The cost of PIZZA is 55 and the cost of BURGER is 39. Therefore Ashish can not buy a PIZZA but can buy a BURGER for his dinner.

Test case-3: Ashish has 30 rupees which are not sufficient to buy either PIZZA or BURGER. Thus he can not buy anything and remains hungry :(.



































Solution

#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--){
     int x,y,z;
     cin>>x>>y>>z;
     if(y<=x){
         cout<<"PIZZA"<<endl;
     }else if(z<=x){
         cout<<"BURGER"<<endl;
     }else{
         cout<<"NOTHING"<<endl;
     }
 }
    return 0;
}