0% found this document useful (0 votes)
4 views

coding que

The document contains multiple programming tasks, each with a description, input/output format, and sample test cases. Tasks include checking if two arrays are the same, finding the type of an array, calculating the sum of array elements, identifying the longest palindrome in an array, computing the minimum scalar product of two vectors, removing duplicates from an array, and determining outcomes for various scenarios involving competition and skills. Each task is accompanied by example code written in C++.

Uploaded by

Vaishnavi Argade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

coding que

The document contains multiple programming tasks, each with a description, input/output format, and sample test cases. Tasks include checking if two arrays are the same, finding the type of an array, calculating the sum of array elements, identifying the longest palindrome in an array, computing the minimum scalar product of two vectors, removing duplicates from an array, and determining outcomes for various scenarios involving competition and skills. Each task is accompanied by example code written in C++.

Uploaded by

Vaishnavi Argade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 127

1) Write Program to check if two arrays are the same or not.

Description:

Get two arrays as the input from the user and check whether it is the same or not.

Sample Input:

Enter the size of first array: n1


Enter the size of second array: n2
Accept elements of array 1
Accept elements of array 2

Sample Output:

Same

Testcase:1[Open Testcase]
Inputs:
3 ,3 ,1 2 3 ,1 2 3
Output:
Same

Testcase:2[Open Testcase]
Inputs:
4 ,4 ,1 2 3 4 ,4 3 2 1
Output:
Same

Testcase:3[Open Testcase]
Inputs:
3 ,2 ,1 2 3 ,1 2
Output:
Not Same

code->

#include<iostream>
using namespace std;
int sort(int arr[], int n)
{
int i,j;
for (i = 0; i < n-1; i++)
{
for (j = 0; j < n-i-1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

int arrays(int arr1[], int arr2[], int n, int m)


{
sort(arr1,n);
sort(arr2,m);
int i;
for(i = 0; i < n; i++)
{
if(arr1[i] != arr2[i])
{
return 0;
}
}
}

int main()
{
int n1, n2;
cout<<"Enter the size of first array: ";
cin>>n1;
cout<<"Enter the size of second array: ";
cin>>n2;
int arr1[n1];
int arr2[n2];
int i;
cout<<"Enter the first array elements: ";
for(i = 0; i < n1; i++)
{
cin>>arr1[i];
}
cout<<"Enter the second array elements: ";
for(i = 0; i < n2; i++)
{
cin>>arr2[i];
}
if(arrays(arr1, arr2, n1, n2) == 0)
{
cout<<"Not same";
}
else
cout<<"Same";
return 0;
}

***********************************************************************************
*************************************************************************

2) Write Program to find the array type

Description:

Get an array as input from the user and check the type of the array, whether it is
odd, even or mixed type.

Input:

Enter size of array:


3
Enter elements
1 3 5
Output:

Odd

Testcase:1[Open Testcase]
Inputs:
4 ,2 4 6 8
Output:
Even

Testcase:2[Open Testcase]
Inputs:
3 ,1 1 1
Output:
Odd

Testcase:3[Open Testcase]
Inputs:
4 ,1 2 3 4
Output:
Mixed

code->

#include<iostream>
using namespace std;
int main()
{
int n;
//cout<<"Enter the size of the array: ";
cin>>n;
int arr[n];
int i;
int o=0, e=0;
//cout<<"Enter the array elements: ";
for(i = 0; i < n; i++)
{
cin>>arr[i];
}
for(i = 0; i < n; i++)
{
if(arr[i] % 2 == 1)
o++;
if(arr[i] % 2 == 0)
e++;
}
if(o == n)
cout<<"Odd";
else if(e == n)
cout<<"Even";
else
cout<<"Mixed";
return 0;
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

3) Write Program to find sum of elements in an array


Description:

Get an array as the input from the user and find the sum of the elements.

Input:

Enter the size of array


3
Enter the elements of array
5 10 15

Output:
30

Testcase:1[Open Testcase]
Inputs:
3 ,0 -1 10
Output:
9

Testcase:2[Open Testcase]
Inputs:
5 ,10 2 10 5 -1
Output:
26

Testcase:3[Open Testcase]
Inputs:
4 ,1 5 -2 10
Output:
14

code->

#include<iostream>
using namespace std;
int Sum(int arr[], int n)
{
int sum = 0;
for(int i = 0; i < n; i++)
sum = sum + arr[i];
return sum;
}
int main()
{
int n;
cout<<"Enter the size of array: ";
cin>>n;
int arr[n];
cout<<"Enter the elements of array: ";
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"Sum: "<<Sum(arr, n);
}

***********************************************************************************
*************************************************************************
4) Write Program to find longest palindrome in an array

Description:

Get an array as the input from the user and find the longest palindrome in that
array. Strictly follow the input and output format.

Input:

Enter the size of array


3
Enter the elements of array
121 10456 1000001

Output:
1000001

Testcase:1[Open Testcase]
Inputs:
3 ,100 11 121
Output:
121

Testcase:2[Open Testcase]
Inputs:
4 ,11 100 121 3
Output:
121

Testcase:3[Open Testcase]
Inputs:
3 ,10001 122222221 11
Output:
122222221

code->

#include<iostream>
#include<limits.h>
using namespace std;
int check(int n){
int rev=0, temp = n;
while(temp>0)
{
int rem = temp%10;
rev = rev*10 + rem;
temp /= 10;
}
if(n==rev)
return 1;
return 0;
}

int main(){
int n;
cout<<"Enter the size of array: ";
cin>>n;
int arr[n];
cout<<"Enter the elements of array: ";
for(int i=0;i<n;i++)
cin>>arr[i];
int res = INT_MIN;
for(int i=0; i<n; i++)
{
if(check(arr[i]) && res<arr[i])
res = arr[i];
}
if(res==INT_MIN)
res = -1;
cout<<"Longest palindrome: "<<res;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

5) Given 2 integer arrays X and Y of same size. Consider both arrays as vectors and
print the minimum scalar product (Dot product) of 2 vectors.

Sample input:
4
1 2 3 4
5 6 7 8

Sample output:
60
Explanation :
(4*5 + 3*6 + 2*7 + 1*8) = 60

Testcase:1[Open Testcase]
Inputs:
4 ,-1 -2 -3 -4 ,5 6 -7 -8
Output:
-17

Testcase:2[Open Testcase]
Inputs:
5 ,1 2 3 4 5 ,5 4 3 2 1
Output:
55

Testcase:3[Open Testcase]
Inputs:
4 ,2 3 1 1 ,5 1 2 4
Output:
20

code->

#include <bits/stdc++.h>
using namespace std;
// SpecialSort function sorts negetive numbers in array1 in ascending order
// and positive numbers and zero in descending order
void SpecialSort(int vec1[],int n)
{
int idx=0;
sort(vec1,vec1+n);
while(vec1[idx] < 0)
{
idx++;
}
int start = idx,end = n-1;
while(start<end)
{
swap(vec1[start],vec1[end]);
start++;end--;
}
}

// Find min product and move the elements to left side of both arrays
int MinimumScalarProduct(int vec1[],int vec2[],int n)
{
int min,sop=0,id1,id2;
for(int i = 0 ; i<n ; i++)
{
min = INT_MAX;
for(int j = i ; j<n ; j++)
{
if((vec1[i]*vec2[j]) < min)
{
min = vec1[i]*vec2[j];
id1 = i; id2 = j;
}
}
sop = sop + min;
swap(vec1[i],vec1[id1]);
swap(vec2[i],vec2[id2]);

}
return sop;
}

int main()
{ int n; cin>>n;
int vec1[n];
for(int i = 0 ; i<n ; i++)
{
cin>>vec1[i];
}
int vec2[n];
for(int i = 0 ; i<n ; i++)
{
cin>>vec2[i];
}
SpecialSort(vec1,n);
cout<<MinimumScalarProduct(vec1,vec2,n);
return 0;
}

###################################################################################
#########################################################################

6) Write Program to remove duplicate elements in an array


Description:

Get an array as input from the user and then remove all the duplicate elements in
that array.

Strictly follow the input and output format.

Input

Enter the size of array

Enter the elements of array

35 35 45 60 60

Output

35 45 60

Testcase:1[Open Testcase]
Inputs:
5 ,1 -2 -2 5 6
Output:
1 -2 5 6

Testcase:2[Open Testcase]
Inputs:
5 ,10 20 30 30 40
Output:
10 20 30 40

Testcase:3[Open Testcase]
Inputs:
4 ,11 22 11 11
Output:
11 22

code->

#include<iostream>
using namespace std;
int dupRemove(int arr[], int n)
{
if (n==0 || n==1)
return n;
int temp[n];
int j = 0;
for(int i=0; i<n-1; i++)
{
if (arr[i] != arr[i+1])
temp[j++] = arr[i];
}
temp[j++] = arr[n-1];
for(int i=0; i<j; i++)
arr[i] = temp[i];
return j;
}
int main()
{
int n;
cout<<"Enter the size of array: ";
cin>>n;
int arr[n];
cout<<"Enter the elements of array: ";
for(int i=0;i<n;i++)
cin>>arr[i];
int s = dupRemove(arr, n);
for (int i=0; i<s; i++)
cout<<arr[i]<<" ";
return 0;
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

7) Win or loose

Amit has reached the finals of the Annual Inter-collage Debate competition.For the
finals, students were asked to prepare 10 topics. However, Amit was only able to
prepare three topics, numbered A, B and C — he is totally blank about the other
topics. This means Amit can only win the contest if he gets the topics A, B or C to
speak about.On the contest day, Amit gets topic X. Determine whether Amit has any
chances of winning the competition.Print "Yes" if it is possible for Amit to win
the contest, else print "No".

Input Format

The first and only line of input will contain a single line containing four space-
separated integers A, B, C, and X — the three topics Amit has prepared and the
topic that was given to him on contest day.

Output Format

For each testcase, output in a single line "Yes" or "No".

Constraints

1≤A,B,C,X≤10

A,B,C are distinct.

Subtasks

Subtask #1 (100 points): Original constraints

Testcase:1[Open Testcase]
Inputs:
2 3 7 3
Output:
Yes

Testcase:2[Open Testcase]
Inputs:
4 6 8 5
Output:
No

code->

#include <iostream>
using namespace std;
int main() {
int a,b,c,x;
cin>>a>>b>>c>>x;
if(a==x || b==x || c==x)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

7) Play games

A study has shown that playing video games helps in increasing one's IQ by 7
points. Ajinkya knows he can't beat Quentin Tarantino, but he wants to try to beat
him in an IQ competition.You know that Quentin Tarantino had an IQ of 160, and
Ajinkya currently has an IQ of X.Determine if, after learning to play video game,
Ajinkya's IQ will become strictly greater than Quentin Tarantino's.Print "Yes" if
it is possible for Ajinkya to beat Quentin Tarantino, else print "No" (without
quotes).

Input Format

The first and only line of input will contain a single integer X, the current IQ of
Ajinkya.

Output Format

For each testcase, output in a single line "Yes" or "No"

Constraints

100≤X≤169

Subtasks

Subtask #1 (100 points): Original constraints

Testcase:1[Open Testcase]
Inputs:
155
Output:
Yes

Testcase:2[Open Testcase]
Inputs:
120
Output:
No
code->

#include <iostream>
using namespace std;
int main() {

int x;
cin>>x;
if((x+7)>160){

cout<<"YES"<<'\n'; }
else{
cout<<"NO"<<endl;
}
return 0;
}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

8) World cup

It is the World Cup Finals. Rohith only finds a match interesting if the skill
difference of the competing teams is less than or equal to D.Given that the skills
of the teams competing in the final are X and Y respectively, determine whether
Rohith will find the game interesting or not.

Input Format

The first line of input will contain a single integer T, denoting the number of
testcases. The description of T testcases follows. Each testcase consists of a
single line of input containing three space-separated integers X, Y, and D — the
skill levels of the teams and the maximum skill difference.

Output Format

For each testcase, output "YES" if Chef will find the game interesting, else output
"NO" (without the quotes).

Constraints

1≤T≤2000

1≤X,Y≤100

0≤D≤100

Testcase:1[Open Testcase]
Inputs:
3 ,5 3 4 ,5 3 1 ,5 5 0
Output:
YES NO YES

code->

#include<bits/stdc++.h>
using namespace std;
int main() {
int i=1;
int T; cin>>T;
int X,Y,D;
for(i=1;i<=T;i++)
{
cin>>X>>Y>>D;
if(abs(X-Y)<=D)
{
cout<<"yes";
}
else{
cout<<"no" }
cout<<"\n";
}
return 0;
}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

9)Swapnil and Races

The Bike Race Championships are starting soon. There are 4 race categories,
numbered from 1 to 4, that Swapnil is interested in. Swapnil is participating in
exactly 2 of these categories.Swapnil has an arch-rival who is, unfortunately, the
only person participating who is better than Swapnil, i.e, Swapnil can't defeat the
arch-rival in any of the four race categories but can defeat anyone else. Swapnil's
arch-rival is also participating in exactly 2 of the four categories.Swapnil hopes
to not fall into the same categories as that of the arch-rival.Given X,Y,A,B where
X,Y are the races that Swapnil participates in, and A,B are the races that
Swapnil's arch-rival participates in, find the maximum number of gold medals (first
place) that Swapnil can win.

Input Format

The first line of input contains an integer T, denoting the number of testcases.
The description of T testcases follows.Each testcase consists of a single line
containing four space-separated integers — the values of X,Y,A, and B respectively.

Output Format

For each testcase, print a single line containing one integer — the maximum number
of gold medals that Swapnil can win.

Constraints

1≤T≤144

1≤X,Y,A,B≤4

X≠Y

A≠B

Subtasks

Subtask #1 (100 points): Original constraints

Testcase:1[Open Testcase]
Inputs:
3 ,4 3 2 1 ,4 2 1 2 ,2 1 1 2
Output:
2 1 0

code->

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int x,y,a,b;
cin>>x>>y>>a>>b;
if(x == a && y == b){
cout<<"0"<<endl;
}
else if(x == b && y == a){
cout<<"0"<<endl;
}
else if(x != a && y == b){
cout<<"1"<<endl;
}
else if(x != b && y == a){
cout<<"1"<<endl;
}
else if(x == a && y != b){
cout<<"1"<<endl;
}
else if(x == b && y != a){
cout<<"1"<<endl;
}
else if(x != a && y!= b){
cout<<"2"<<endl;
}
else if(x != b && y != a){
cout<<"2"<<endl;
}
}
return 0;
}

***********************************************************************************
*************************************************************************

10) Economics Class

Vaishnavi has recently learned in her Economics class that the market is said to be
in equilibrium when the supply is equal to the demand.Vaishnavi has market data for
N time points in the form of two integer arrays S and D. Here, Si denotes the
supply at the ith point of time and Di denotes the demand at the ith point of time,
for each 1≤i≤N.Help Vaishnavi in finding out the number of time points at which the
market was in equilibrium.

Input Format

The first line of input will contain an integer T — the number of test cases. The
description of T test cases follows.

Each test case contains three lines of input.The first line of each test case
contains an integer N, the length of the arrays S and D.The second line of each
test case contains N space-separated integers S1,S2,…,SN.The third line of each
test case contains N space-separated integers D1,D2,…,DN.

Output Format

For each test case, output the number of time points at which the market was in
equilibrium.

Constraints

1≤T≤10

1≤N≤100

1≤Si,Di≤100 for every 1≤i≤N

Testcase:1[Open Testcase]
Inputs:
2 ,4 ,1 2 3 4 ,2 1 3 4 ,4 ,1 1 2 2 ,1 2 1 1
Output:
2 1

code->

#include <bits/stdc++.h>
using namespace std;
int main() {
int t , n, arr1[100],arr2[100];
cin>>t;
for (int i = 0; i < t; i++) {
int count=0;
cin>>n;
for (int j = 0; j < n; j++) {
cin>>arr1[j];
}

for (int j = 0; j < n; j++) {


cin>>arr2[j];
}
for (int j = 0; j < n; j++) {
if(arr1[j]==arr2[j])
{
count++;
}
}
std::cout << count << std::endl;
}
return 0;
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

11) Pass or Fail


Anusree is struggling to pass a certain college course.The test has a total of N
question, each question carries 3 marks for a correct answer and −1 for an
incorrect answer. Anusree is a risk-averse person so he decided to attempt all the
questions. It is known that Anusree got X questions correct and the rest of them
incorrect. For Anusree to pass the course he must score at least P marks.Will
Anusree be able to pass the exam or not?

Input Format

First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, three integers N, X, P.

Output Format

For each test case output "PASS" if Chef passes the exam and "FAIL" if Chef fails
the exam.

You may print each character of the string in uppercase or lowercase (for example,
the strings "pAas", "pass", "Pass" and "PASS" will all be treated as identical).

Testcase:1[Open Testcase]
Inputs:
3 ,5 2 3 ,5 2 4 ,4 0 0
Output:
PASS FAIL FAIL

code->

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,x,p;
cin>>n>>x>>p;
int marks=4*x-n;
if(marks>=p){
cout<<"pass"<<'\n';
}
else{
cout<<"fail"<<'\n';
}
}
return 0;
}

###################################################################################
#########################################################################

12) Body Mass Index

You are given the height H (in metres) and mass M (in kilograms) of Anusree. The
Body Mass Index (BMI) of a person is computed as M/H^2.
Report the category into which Anusree falls, based on his BMI:

Category 1: Underweight if BMI ≤18


Category 2: Normal weight if BMI ∈{19, 20,…, 24}

Category 3: Overweight if BMI ∈{25, 26,…, 29}

Category 4: Obesity if BMI ≥30

Input:

The first line of input will contain an integer, T, which denotes the number of
testcases. Then the testcases follow.

Each testcase contains a single line of input, with two space separated integers,
M,H, which denote the mass and height of Anusree respectively.

Output:

For each testcase, output in a single line, 1,2,3 or 4, based on the category in
which Anusree falls.

Testcase:1[Open Testcase]
Inputs:
3 ,72 2 ,80 2 ,120 2
Output:
1 2 4

code->

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int m,h;
cin>>m>>h;
int BMI=m/(h*h);
if (BMI<=18){
cout<<1<<endl;
}
else if(BMI>18&&BMI<=24){
cout<<2<<endl;
}
else if(BMI>24&&BMI<=29){
cout<<3<<endl;
}
else{
cout<<4<<endl;
}
}
return 0;
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

13) Bucket Filling


Nejiya has a bucket having a capacity of K liters. It is already filled with X
liters of water. Find the maximum amount of extra water in liters that Nejiya can
fill in the bucket without overflowing.

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 two space separated integers K
and X - as mentioned in the problem.

Output Format

For each test case, output in a single line, the amount of extra water in liters
that Nejiya can fill in the bucket without overflowing.

Testcase:1[Open Testcase]
Inputs:
2 ,5 4 ,15 6
Output:
1 9

code->

#include <iostream>
using namespace std;
int main() {
int a;
cin>>a;
while(a--){
int b,c;
cin>>b>>c;
cout<<b-c<<"\n";
}
return 0;
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

14) Good Weather

The weather report of Magicland is Good if the number of sunny days in a week is
strictly greater than the number of rainy days.Given 7 integers
A1,A2,A3,A4,A5,A6,A7 where Ai=1 denotes that the ith day of week in Magicland is a
sunny day, Ai=0 denotes that the ith day in Magicland is a rainy day. Determine if
the weather report of Magicland is Good or not.

Input Format

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, 7 space separated integers


A1,A2,A3,A4,A5,A6,A7.

Output Format
For each testcase, print "YES" if the weather report of Magicland is Good,
otherwise print "NO". Print the output without quotes.

You may print each character of the string in uppercase or lowercase (for example,
the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Testcase:1[Open Testcase]
Inputs:
4 ,1 0 1 0 1 1 1 ,0 1 0 0 0 0 1 ,1 1 1 1 1 1 1 ,0 0 0 1 0 0 0
Output:
YES NO YES NO

code->

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
for(int i=0;i<t;i++){
int arr[7];
for(int j=0;j<7;j++){
cin>>arr[j];}
int a=0,b=0;
for(int j=0;j<7;j++)
{ if(arr[j]==1)
{ a++;}
else{ b++;}
}
if(a>b)
cout<<"YES\n";
else
cout<<"NO\n";
}
}
return 0;
}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

15) Chess Format

Given the time control of a chess match as a+b, determine which format of chess out
of the given 4 it belongs to.

1) Bullet if a+b<3

2) Blitz if 3≤a+b≤10

3) Rapid if 11≤a+b≤60

4) Classical if 60<a+b

Input Format
First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains a single line of input, two integers a,b

Output Format

For each testcase, output in a single line, answer 1 for bullet, 2 for blitz, 3 for
rapid, and 4 for classical format.

Testcase:1[Open Testcase]
Inputs:
4 ,1 0 ,4 1 ,100 0 ,20 5
Output:
1 2 4 3

code->

#include <iostream>
using namespace std;
int main() {
int T;
cin>>T;
while(T--){
int a,b;
cin>>a>>b;
if((a+b)<3){
cout<<"1"<<endl; }
else if(((a+b)>=3)&&((a+b)<=10)){
cout<<"2"<<endl;}
else if(((a+b)>=11)&&((a+b)<=60)){
cout<<"3"<<endl;}
else{
cout<<"4"<<endl; }
}
return 0;
}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

16) ATM Machine

There is an ATM machine. Initially, it contains a total of K units of money. N


people (numbered 1 through N) want to withdraw money; for each valid i, the i-th
person wants to withdraw Ai units of money.The people come in and try to withdraw
money one by one, in the increasing order of their indices. Whenever someone tries
to withdraw money, if the machine has at least the required amount of money, it
will give out the required amount. Otherwise, it will throw an error and not give
out anything; in that case, this person will return home directly without trying to
do anything else.For each person, determine whether they will get the required
amount of money or not.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains two space-separated integers N and K.
The second line contains N space-separated integers A1,A2,…,AN

Output

For each test case, print a single line containing a string with length N. For each
valid i, the i-th character of this string should be '1' if the i-th person will
successfully withdraw their money or '0' otherwise.

Testcase:1[Open Testcase]
Inputs:
2 ,5 10 ,3 5 3 2 1 ,4 6 ,10 8 6 4
Output:
11010 0010

code->

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,k,i;
cin>>n>>k;
int s=k;
for(i=0;i<n;i++)
{
int a;
cin>>a;
if(s<a)
cout<<"0";
else
{
cout<<"1";
s=s-a;
}
cout<<endl;
}
return 0;
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

17) Gold Mining

Anusree has decided to go to a gold mine along with N of his friends (thus, total
N+1 people including Anusree go to the gold mine).The gold mine contains a total of
X kg of gold. Every person has the capacity of carrying up atmost Y kg of gold.Will
Anusree and his friends together be able to carry up all the gold from the gold
mine assuming that they can go to the mine exactly once.

Input Format

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, three integers N, X, Y.


Output Format

For each testcase, output "YES" if you and your friends can carry all the gold,
otherwise output "NO".

You may print each character of the string in uppercase or lowercase (for example,
the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Testcase:1[Open Testcase]
Inputs:
3 ,2 10 3 ,2 10 4 ,1 5 10
Output:
NO YES YES

code->

#include<bits/stdc++.h>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,g,c;
cin>>n>>g>>c;
if(((n+1)*c)>=g){
cout<<"YES"<<endl;}
else{
cout<<"NO"<<endl;}
}
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

18) Balancing Weight

No play and eating all day makes your belly fat. This happened to Manish during the
lockdown. His weight before the lockdown was w1 kg (measured on the most accurate
hospital machine) and after M months of lockdown, when he measured his weight at
home (on a regular scale, which can be inaccurate), he got the result that his
weight was w2 kg (w2>w1).
Scientific research in all growing kids shows that their weights increase by a
value between x1 and x2 kg (inclusive) per month, but not necessarily the same
value each month. Manish assumes that he is a growing kid. Tell him whether his
home scale could be giving correct results.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first and only line of each test case contains five space-separated integers
w1, w2, x1, x2 and M.

Output
For each test case, print a single line containing the integer 1 if the result
shown by the scale can be correct or 0 if it cannot.

Testcase:1[Open Testcase]
Inputs:
5 ,1 2 1 2 2 ,2 4 1 2 2 ,4 8 1 2 2 ,5 8 1 2 2 ,1 100 1 2 2
Output:
0 1 1 1 0

code->

for i in range (int(input())):


w1,w2,x1,x2,M=map(int,input().split(" "))
h=(w2-w1)
s1=x1*M
s2=x2*M
if (h>=s1 and h<=s2):
print("1")
else:
print("0")

###################################################################################
########################################################################

19) TCS Examination

Two friends, Arun and Akhil, are writing a computer science examination series.
There are three subjects in this series: DSA, TOC, and DM. Each subject carries 100
marks.

You know the individual scores of both Arun and Akhil in all 3 subjects. You have
to determine who got a better rank.

The rank is decided as follows:

The person with a bigger total score gets a better rank

If the total scores are tied, the person who scored higher in DSA gets a better
rank

If the total score and the DSA score are tied, the person who scored higher in TOC
gets a better rank

If everything is tied, they get the same rank.

Input Format

The first line of input contains a single integer T, denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains three space-separated integers denoting
the scores of Arun in DSA, TOC and DM respectively.

The second line of each test case contains three space-separated integers denoting
the scores of Akhil in DSA, TOC and DM respectively.

Output Format
For each test case, if Arun got a better rank then output "Arun", else if Akhil got
a better rank then output "Akhil". If there was a tie then output "Tie". Note that
the string you output should not contain quotes.

The output is case insensitive. For example, If the output is "Tie" then "TiE",
"tiE", "tie", etc are also considered correct.

Testcase:1[Open Testcase]
Inputs:
4 ,10 20 30 ,30 20 10 ,5 23 87 ,5 23 87 ,0 15 100 ,100 5 5 ,50 50 50 ,50 49 51
Output:
AKHIL TIE ARUN ARUN

code->

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int d1,t1,m1,d2,t2,m2;
cin>>d1>>t1>>m1;
cin>>d2>>t2>>m2;
int total1 = d1+t1+m1;
int total2 = d2+t2+m2;
if(total1 > total2){
cout<<"ARUN"<<end;
goto end;}
else if(total1 < total2) {
cout<<"AKHIL"<<endl;
goto end;}
else{
if(d1>d2)
{
cout<<"ARUN"<<endl;
goto end;}
else if(d1<d2){
cout<<"AKHIL"<<endl;
goto end;}
else{
if(t1>t2){
cout<<"ARUN"<<endl;
goto end;}
else if(t1<t2)
{
cout<<"AKHIL"<<endl;
goto end;
}
else{
cout<<"TIE"<<endl;
goto end;
}
}
}

***********************************************************************************
************************************************************************
20) Amit and Feedback

Lots of geeky customers visit our Amit's restaurant everyday. So, when asked to
fill the feedback form, these customers represent the feedback using a binary
string (i.e a string that contains only characters '0' and '1'.

Now since Amit is not that great in deciphering binary strings, he has decided the
following criteria to classify the feedback as Good or Bad :

If the string contains the substring "010" or "101", then the feedback is Good,
else it is Bad. Note that, to be Good it is not necessary to have both of them as
substring.

So given some binary strings, you need to output whether according to the Amit, the
strings are Good or Bad.

Input

The first line contains an integer T denoting the number of feedbacks. Each of the
next T lines contains a string composed of only '0' and '1'.

Output

For every test case, print in a single line Good or Bad as per the Amit's method of
classification.

Testcase:1[Open Testcase]
Inputs:
2 ,11111110 ,10101010101010
Output:
Bad Good

code->

#include <iostream>

using namespace std;

int main() {

int t;cin>>t;

while(t--){

string s;cin>>s;
bool found=false;

if(s.find("101")!=string::npos||s.find("010")!=string::npos ){

found=true;

cout<<(found ? "Good":"Bad");

cout<<endl;

return 0;

***********************************************************************************
************************************************************************

21) Studying Alphabet

Not everyone probably knows that Amit has younger brother Anoop. Currently Anoop
learns to read.

He knows some subset of the letter of Latin alphabet. In order to help Anoop to
study, Amit gave him a book with the text consisting of N words. Anoop can read a
word if it consists only of the letters he knows.

Now Amit is curious about which words his brother will be able to read, and which
are not. Please help him!

Input

The first line of the input contains a lowercase Latin letter string S, consisting
of the letters Anoop can read. Every letter will appear in S no more than once.

The second line of the input contains an integer N denoting the number of words in
the book.

Each of the following N lines contains a single lowercase Latin letter string Wi,
denoting the ith word in the book.

Output

For each of the words, output "Yes" (without quotes) in case Jeff can read it, and
"No" (without quotes) otherwise.

Testcase:1[Open Testcase]
Inputs:
act ,2 ,cat ,dog
Output:
Yes No

code->

#include <bits/stdc++.h>

using namespace std;

int main() {

string s;

cin>>s;

int t;

cin>>t;

while(t--){

int count = 0;

string a,b,c;
cin>>a;

for(int i=0;i<a.size();i++){

for(int j=0;j<s.size();j++){

if(a[i]==s[j]){

count++;

if(count==a.size()){

cout<<"Yes"<<endl;

else{

cout<<"No"<<endl;

}
return 0;

***********************************************************************************
*************************************************************************

22) The Squid Game

Squid Game has become a blockbuster hit and the frontman is now finding it
difficult to accommodate all the participants in Squid Game 2.0. So, he decided
that he will allow only those participants who could solve the following problem.

There are a total of N players who are competing in the Squid Game, numbered from 1
to N. When the ith player gets eliminated from the game, Ai amount of money is
added to the prize pool. The game is played until N−1 players get eliminated, and
the only player left is declared as the winner. The winner gets all the money
present in the prize pool.

You are given an array A consisting of N elements, where Ai denotes the prize money
added to the prize pool when the ith player gets eliminated from the game. Find the
maximum prize that the winner can get, given that you can choose any player to be
the winner.

Input Format

The first line of input contains a single integer T, denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains an integer N, denoting the number of
players.

The second line of each test case contains N space-separated integers A1,A2,…,AN,
denoting the amount of money added to the prize pool when the ith (1≤i≤N) player
dies.

Output Format

For each test case, output in a single line the maximum prize that the winner can
get, given that you can choose any player to be the winner.

Testcase:1[Open Testcase]
Inputs:
3 ,3 ,3 1 2 ,5 ,1 1 1 1 1 ,6 ,3 6 4 2 5 1
Output:
5 4 20

code->

#include <iostream>
using namespace std;

int main()

int x, y;

cin >> x;

for (int j = 0; j < x; j++)

cin >> y;

int z, a = 0, temp = 999999;

for (int i = 0; i < y; i++)

cin >> z;
a += z;

if (z < temp)

temp = z;

a = a - temp;

cout << a << endl;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

23) My Score

You are participating in a contest which has 11 problems (numbered 1 through 11).
The first eight problems (i.e. problems 1,2,…,8) are scorable, while the last three
problems (9, 10 and 11) are non-scorable ― this means that any submissions you make
on any of these problems do not affect your total score.

Your total score is the sum of your best scores for all scorable problems. That is,
for each scorable problem, you look at the scores of all submissions you made on
that problem and take the maximum of these scores (or 0 if you didn't make any
submissions on that problem); the total score is the sum of the maximum scores you
took.

You know the results of all submissions you made. Calculate your total score.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains a single integer N denoting the number of
submissions you made.

N lines follow. For each i (1≤i≤N), the i-th of these lines contains two space-
separated integers pi and si, denoting that your i-th submission was on problem pi
and it received a score si.

Output

For each test case, print a single line containing one integer ? your total score.

Testcase:1[Open Testcase]
Inputs:
2 ,5 ,2 45 ,9 100 ,8 0 ,2 15 ,8 90 ,1 ,11 1
Output:
135 0

code->

#include <iostream>

using namespace std;

int main() {

int n;

cin>>n;

while(n--){
int a;

cin>>a;

int arr1[a],arr2[a];

int arr3[8]={0};

for(int i=0; i<a; i++){

cin>>arr1[i]>>arr2[i];

for(int i=0; i<a; i++){

if(arr1[i]<=8){

if(arr2[i]>arr3[arr1[i]-1]){

arr3[arr1[i]-1]=arr2[i];

int sum =0;


for(int i=0; i<8; i++){

sum+=arr3[i];

cout<<sum<<endl;

return 0;

###################################################################################
#########################################################################

24) Palindromic substrings

Anoop likes strings a lot but he likes palindromic strings more. Today, Anoop has
two strings A and B, each consisting of lower case alphabets.

Anoop is eager to know whether it is possible to choose some non empty strings s1
and s2 where s1 is a substring of A, s2 is a substring of B such that s1 + s2 is a
palindromic string. Here '+' denotes the concatenation between the strings.

Input

First line of input contains a single integer T denoting the number of test cases.

For each test case:

First line contains the string A

Second line contains the string B.

Output

For each test case, Print "Yes" (without quotes) if it possible to choose such
strings s1 & s2. Print "No" (without quotes) otherwise.

Testcase:1[Open Testcase]
Inputs:
3 ,abc ,abc ,a ,b ,abba ,baab
Output:
Yes No Yes

code->

#include <iostream>

#include <algorithm>

using namespace std;

int main() {

int n;

cin >> n;

while(n--)

string s1="", s2="";

cin >> s1 >> s2;

int flag = 0;

for(int i=0; i<s1.size(); i++)


{

for(int j=0; j<s2.size(); j++)

if(s1[i] == s2[j])

flag++;

if(flag > 0)

cout << "Yes" << endl;

else

cout << "No" << endl;

return 0;
}

***********************************************************************************
*************************************************************************

25) New Tablet

Ajinkya decided to buy a new tablet. His budget is B, so he cannot buy a tablet
whose price is greater than B. Other than that, he only has one criterion — the
area of the tablet's screen should be as large as possible. Of course, the screen
of a tablet is always a rectangle.

Ajinkya has visited some tablet shops and listed all of his options. In total,
there are N available tablets, numbered 1 through N. For each valid i, the i-th
tablet has width Wi, height Hi and price Pi.

Help Ajinkya choose a tablet which he should buy and find the area of such a
tablet's screen, or determine that he cannot buy any tablet.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains two space-separated integers N and B.

N lines follow. For each i (1≤i≤N), the i-th of these lines contains three space-
separated integers Wi, Hi and Pi.

Output

For each test case, print a single line. If Ajinkya cannot buy any tablet, it
should contain the string "no tablet" (without quotes). Otherwise, it should
contain a single integer — the maximum area of the screen of a tablet Ajinkya can
buy.

Testcase:1[Open Testcase]
Inputs:
3 ,3 6 ,3 4 4 ,5 5 7 ,5 2 5 ,2 6 ,3 6 8 ,5 4 9 ,1 10 ,5 5 10
Output:
12 no tablet 25

code->

#include <iostream>

using namespace std;

int main() {
int t;

cin>>t;

while(t--)

int n,b;

cin>>n>>b;

int max=-1;

for(int i=0;i<n;i++)

int width,height,price;

cin>>width>>height>>price;

int area=width*height;

if(price<=b)

if(area>max)
max=area;

if(max==-1)

cout<<"no tablet\n";

else

cout<<max<<"\n";

return 0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

26) Car or Bus

Amit wants to reach home as soon as possible. He has two options:

Travel with his BIKE which takes X minutes.

Travel with his CAR which takes Y minutes.

Which of the two options is faster or do they both take same time?

Input Format

First line will contain T, number of test cases. Then the test cases follow.

Each test case contains a single line of input, two integers X, Y representing the
time taken to travel with BIKE and CAR respectively.
Output Format

For each test case, print CAR if travelling with Car is faster, BIKE if travelling
with Bike is faster, SAME if they both take the same time.

You may print each character of CAR, BIKE and SAME in uppercase or lowercase (for
example, CAR, Car, cAr will be considered identical).

Testcase:1[Open Testcase]
Inputs:
3 ,1 5 ,4 2 ,6 6
Output:
BIKE CAR SAME

code->

#include <bits/stdc++.h>

using namespace std;

int main()

int t;

cin>>t;

for(int i=0;i<t;i++)

int x,y;

cin>>x>>y;

if(x<y)
cout<<"BIKE"<<endl;

else if(y<x)

cout<<"CAR"<<endl;

else

cout<<"SAME"<<endl;

return 0;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

27) Bricks Breaking

For her next karate demonstration, Arunima will break some bricks.

Arunima stacked three bricks on top of each other. Initially, their widths (from
top to bottom) are W1,W2,W3.

Arunima strength is S. Whenever she hits a stack of bricks, consider the largest
k≥0 such that the sum of widths of the topmost k bricks does not exceed S; the
topmost k bricks break and are removed from the stack. Before each hit, Arunima may
also decide to reverse the current stack of bricks, with no cost.

Find the minimum number of hits Arunima needs in order to break all bricks if she
performs the reversals optimally. You are not required to minimize the number of
reversals.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first and only line of each test case contains four space-separated integers S,
W1, W2 and W3.

Output

For each test case, print a single line containing one integer ? the minimum
required number of hits.

Testcase:1[Open Testcase]
Inputs:
3 ,3 1 2 2 ,2 1 1 1 ,3 2 2 1
Output:
2 2 2

code->

#include <iostream>

using namespace std;

int main() {

int t;

int count=0;

cin>>t;

while(t--)

{ int count=0;

int s,a,b,c;

cin>>s>>a>>b>>c;

if((a+b+c)<=s)
{

count=1;

else if((a+b)<=s || (c+b)<=s)

count = 2;

else

count=3;

cout<<count<<endl;

return 0;

###################################################################################
#########################################################################

28) Qualify the round

In a coding contest, there are two types of problems:

Easy problems, which are worth 1 point each

Hard problems, which are worth 2 points each

To qualify for the next round, a contestant must score at least X points. Amit
solved A Easy problems and B Hard problems. Will Amit qualify or not?

Input Format

The first line of input contains a single integer T, denoting the number of test
cases. The description of T test cases follows.

Each test case consists of a single line of input containing three space-separated
integers — X, A, and B.

Output Format

For each test case, output a new line containing the answer — Qualify if Amit
qualifies for the next round, and Not Qualify otherwise.

Each character of the answer may be printed in either uppercase or lowercase. For
example, if the answer is Qualify, outputs such as qualify, quALiFy, QUALIFY and
QuAlIfY will also be accepted as correct.

Testcase:1[Open Testcase]
Inputs:
3 ,15 9 3 ,5 3 0 ,6 2 8
Output:
Qualify NotQualify Qualify

code->

#include <iostream>

using namespace std;

int main()

{ int t;

cin>>t;
while(t-->0)

int x,a,b;

cin>>x>>a>>b;

if((a+(b*2))>=x)

cout<<"Qualify\n";

else

cout<<"NotQualify\n";

return 0;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

29)The Great Run

Varun loves running. He often visits his favourite Nehru Park and runs for very
long distances. On one such visit he found that the number of girls in the park was
unusually high. Now he wants to use this as an opportunity to impress a large
number of girls with his awesome speed.

The track on which he runs is an N kilometres long straight path. There are ai
girls standing within the ith kilometre of this path. A girl will be impressed only
if Varun is running at his maximum speed when he passes by her. But he can run at
his best speed only for a single continuous stretch of K kilometres. Now Varun
wants to know what is the maximum number of girls that he can impress.

Input

First line of the input contains the number of testcases T.

For each test case,

First line contains two space-separated integers N and K, the length of the track
and the maximum distance he can run at his best speed.

Second line contains N space-separated integers, the number of girls within each
kilometre of the track.

Output

For each test case print one line containing an integer, denoting the maximum
number of girls Varun can impress.

Testcase:1[Open Testcase]
Inputs:
1 ,7 2 ,2 4 8 1 2 1 8
Output:
12

code->

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int main() {

int t;

cin>>t;
while(t>0)

int n,k;

cin>>n>>k;

vector<int>a;

int x;

for(int i=0;i<n;i++)

cin>>x;

a.push_back(x);

int c=0,s=0;

for(int i=0;i<k;i++)

s+=a[i];
c+=a[i];

for(int i=k;i<n;i++)

c+=a[i];

c-=a[i-k];

s=max(s,c);

cout<<s<<endl;

t--;

return 0;

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

30) Find the Direction(onlt c)

Amit is currently facing the north direction. Each second he rotates exactly 90
degrees in clockwise direction. Find the direction in which Amit is facing after
exactly X seconds.
Note: There are only 4 directions: North, East, South, West (in clockwise order).

Input Format

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single integer X.

Output Format

For each testcase, output the direction in which Amit is facing after exactly X
seconds.

Testcase:1[Open Testcase]
Inputs:
3 ,1 ,3 ,6
Output:
East West South

Testcase:2[Open Testcase]
Inputs:
2 ,5 ,4
Output:
East North

code->

#include <stdio.h>

int main()

int n,i=0,N;

printf("");

scanf("%d",&n);

while(n>i)

{
scanf("%d",&N);

if(N%2==0)

if(N%4==0)

printf("North\n");

else

printf("South\n");

else

if((N-1)%4==0)
{

printf("East\n");

else

printf("West\n");

i=i+1;

return 0;

***********************************************************************************
***********************************************************************

31) Save Water Save Life

To address the situation of Water Scarcity in Talentland, Arun has started an


awareness campaign to motivate people to use greywater for toilets, washing cars,
gardening, and many other chores which don't require the use of freshwater. These
activities presently consume y liters of water every week per household and Arun
thinks through this campaign he can help cut down the total usage to ⌊y/2⌋.

Assuming x liters of water every week per household is consumed at chores where
using freshwater is mandatory and a total of C liters of water is available for the
entire Talentland having H households for a week, find whether all the households
can now have sufficient water to meet their requirements

Input:

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, four integers H,x,y,C.

Output:

Print a single line containing the string "YES" if it is possible to meet the
requirement of all the households in Talentland or "NO" if it is impossible
(without quotes).

Testcase:1[Open Testcase]
Inputs:
3 ,3 1 1 3 ,1 1 1 2 ,2 1 1 1
Output:
YES YES NO

Testcase:2[Open Testcase]
Inputs:
2 ,2 2 1 4 ,3 4 5 6
Output:
YES NO

Testcase:3[Open Testcase]
Inputs:
2 ,2 1 4 5 ,3 5 2 1
Output:
NO NO

code->

#include<iostream>

using namespace std;

int main(){

int t;

cin>>t;
while(t--){

int H,x,y,C,t,i;

cin>>H>>x>>y>>C;

i=y/2;

t= H*(x + i);

if(t>C)

cout<<"NO"<<endl;

else

cout<<"YES"<<endl;

return 0;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

32) The Preparations(java)

Amit has an exam which will start exactly M minutes from now. However, instead of
preparing for his exam, Amit started watching Season-1 of Superchef. Season-1 has N
episodes, and the duration of each episode is K minutes.

Will Amit be able to finish watching Season-1 strictly before the exam starts?

Note: Please read the explanations of the sample test cases carefully.
Input Format

The first line contains an integer T denoting the number of test cases. T test
cases then follow.

The first and only line of each test case contains 3 space separated integers M, N
and K.

Output Format

For each test case, output on one line YES if it is possible to finish Season-1
strictly before the exam starts, or NO if it is not possible to do so.

Testcase:1[Open Testcase]
Inputs:
3 ,10 1 10 ,25 2 10 ,15 2 10
Output:
NO YES NO

Testcase:2[Open Testcase]
Inputs:
2 ,3 1 2 ,4 5 6
Output:
YES NO

Testcase:3[Open Testcase]
Inputs:
3 ,6 15 31 ,15 20 50 ,25 2 11
Output:
NO NO YES

code->

import java.util.*;

import java.lang.*;

import java.io.*;

class Main

public static void main (String[] args) throws java.lang.Exception


{

try {

Scanner sc=new Scanner(System.in);

int test=sc.nextInt();

for(int i=1;i<=test; i++){

int M=sc.nextInt();

int N=sc.nextInt();

int K=sc.nextInt();

int NK=N*K;

if(NK < M){

System.out.println("Yes");

else{

System.out.println("No");

}
}

} catch(Exception e) {

return;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

33) Cars and Bikes

Sam opened a company which manufactures cars and bikes. Each car requires 4 Tyres
while each bike requires 2 Tyres. Sam has a total of N Tyres (N is even). He wants
to manufacture maximum number of cars from these Tyres and then manufacture bikes
from the remaining Tyres.

Sam's friend went to Sam to purchase a bike. If Sam's company has manufactured even
a single bike, then Sam's friend will be able to purchase it.

Determine whether he will be able to purchase the bike or not

Input Format

The first line contains an integer T denoting the number of test cases. The T test
cases then follow.

The first line of each test case contains an integer N denoting the number of
Tyres.

Output Format

For each test case, output YES or NO depending on whether Sam's friend will be able
to purchase the bike or not.

Testcase:1[Open Testcase]
Inputs:
3 ,8 ,2 ,6
Output:
NO YES YES

Testcase:2[Open Testcase]
Inputs:
2 ,7 ,10
Output:
YES YES

Testcase:3[Open Testcase]
Inputs:
2 ,4 ,9
Output:
NO YES

code->

t=int(input())

for i in range(t):

n=int(input())

if(n%4 == 0):

print("NO")

else:

print("YES")

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

34) The Largest Bouquet

It's autumn now, the time of the leaf fall.

Sam likes to collect fallen leaves in autumn. In his city, he can find fallen
leaves of maple, oak and poplar. These leaves can be of three different colors:
green, yellow or red.

Sam has collected some leaves of each type and color. Now he wants to create the
biggest nice bouquet from them. He considers the bouquet nice if all the leaves in
it are either from the same type of tree or of the same color (or both). Moreover,
he doesn't want to create a bouquet with even number of leaves in it, since this
kind of bouquets are considered to attract bad luck. However, if it's impossible to
make any nice bouquet, he won't do anything, thus, obtaining a bouquet with zero
leaves.

Please help Sam to find the maximal number of leaves he can have in a nice bouquet,
which satisfies all the above-mentioned requirements.

Please note that Sam doesn't have to use all the leaves of the same color or of the
same type. For example, if he has 20 maple leaves, he can still create a bouquet of
19 leaves

Input

The first line of the input contains an integer T denoting the number of test
cases. The description of T test cases follows."

The first line of each test case contains three space-separated integers MG MY MR
denoting the number of green, yellow and red maple leaves respectively.

The second line contains three space-separated integers OG OY OR denoting the


number of green, yellow and red oak leaves respectively.

The third line of each test case contains three space-separated integers PG PY PR
denoting the number of green, yellow and red poplar leaves respectively.

Output

For each test case, output a single line containing the maximal number of flowers
in nice bouquet, satisfying all conditions or 0 if it's impossible to create any
bouquet, satisfying the conditions.

Testcase:1[Open Testcase]
Inputs:
1 ,1 2 3 ,3 2 1 ,1 3 4
Output:
7

code->

#include <iostream>

#define ll long long

using namespace std;

int main() {

int test;
ll arr[3][3];

cin >> test;

while(test--){

for(int i = 0; i < 3; ++i){

for(int j = 0; j < 3; ++j)

cin >> arr[i][j];

ll maxi = 0, sum;

for(int i = 0; i < 3; ++i){

sum = 0;

for(int j = 0; j < 3; ++j){

sum += arr[i][j];

if(sum % 2 == 0)

sum = sum-1;
if(sum > maxi)

maxi = sum;

for(int i = 0; i < 3; ++i){

sum = 0;

for(int j = 0; j < 3; ++j){

sum += arr[j][i];

if(sum % 2 == 0)

sum = sum-1;

if(sum > maxi)

maxi = sum;

}
cout << maxi << endl;

return 0;

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

35) Name Reduction

In an attempt to reduce the growing population, Arun was asked to come up with a
plan. Arun being as intelligent as he is, came up with the following plan:

If N children, with names C1,C2,...,CN, are born to parents with names A and B, and
you consider C to be the concatenation of all the names of the children, i.e.
C=C1+C2+...+CN (where + is concatenation operator), then C should be a substring of
one of the permutations of A+B.

You are given the task to verify whether the names parents propose to give their
children are in fact permissible by Arun's plan or not.

Input

The first line contains an integer T, the number of test cases. T test cases
follow. Each test case stats with a line containing two space separated strings A
and B, denoting the names of the parents. The next line contains a single integer N
denoting the number of children A and B are planning to have. Following this are N
lines, the ith line containing Ci, the proposed name for the ith child.

Output

For each test case output a single line containing YES if the names are permissible
by Arun's plan, otherwise print NO.

Testcase:1[Open Testcase]
Inputs:
3 ,tom marvoloriddle ,2 ,lord ,voldemort ,cheap up ,1 ,heapcup ,bruce wayne ,2 ,bat
,man
Output:
YES YES NO
code->

#include <bits/stdc++.h>

using namespace std;

int main() {

int t;cin>>t;

while(t--){

string a,b;

cin>>a>>b;

vector <int> v(26);

for(int i=0;i<a.length();i++){

v[a[i]-97]++;

for(int i=0;i<b.length();i++){

v[b[i]-97]++;

}
bool f=true;

int n;cin>>n;

for(int i=1;i<=n;i++){

string c;cin>>c;

for(int j=0;j<c.length();j++){

if(v[c[j]-97] > 0){

v[c[j]-97]--;

else{

f=false;

break;

if(f){
cout<<"YES"<<'\n';

else{

cout<<"NO"<<"\n";

return 0;

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

36) Problem Category

Amit prepared a problem. The admin has rated this problem for x points.

A problem is called :

1) Easy if 1≤x<100

2) Medium if 100≤x<200

3) Hard if 200≤x≤300

Find the category to which Amit’s problem belongs.

Input Format

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

The first and only line of each test case contains a single integer x.

Output Format

For each test case, output in a single line the category of Amit's problem, i.e
whether it is an Easy, Medium or Hard problem. The output is case sensitive.

Testcase:1[Open Testcase]
Inputs:
3 ,50 ,172 ,201
Output:
Easy Medium Hard

Testcase:2[Open Testcase]
Inputs:
2 ,76 ,89
Output:
Easy Easy

Testcase:3[Open Testcase]
Inputs:
2 ,156 ,230
Output:
Medium Hard

code->

#include<iostream>

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

int x;

cin>>x;

if(x>=1 && x<100){

cout<<"Easy"<<endl;
}

if(x>=100 && x<200){

cout<<"Medium"<<endl;

if(x>=200 && x<=300)

cout<<"Hard"<<endl;

return 0;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

37) Find the Direction

Amit is currently facing the north direction. Each second he rotates exactly 90
degrees in clockwise direction. Find the direction in which Amit is facing after
exactly X seconds.

Note: There are only 4 directions: North, East, South, West (in clockwise order).

Input Format
First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single integer X.

Output Format

For each testcase, output the direction in which Amit is facing after exactly X
seconds.

Testcase:1[Open Testcase]
Inputs:
3 ,1 ,3 ,6
Output:
East West South

Testcase:2[Open Testcase]
Inputs:
2 ,5 ,4
Output:
East North

Testcase:3[Open Testcase]
Inputs:
4 ,6 ,2 ,7 ,8
Output:
South South West North

code->

#include <bits/stdc++.h>

using namespace std;

string DIRECTIONS[] = {"North", "East", "South", "West"};

int main()

int t;

cin >> t;

while (t-- > 0)


{

int x;

cin >> x;

cout << DIRECTIONS[x % 4] << endl;

return 0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

38) Save Water Save Life

To address the situation of Water Scarcity in Talentland, Arun has started an


awareness campaign to motivate people to use greywater for toilets, washing cars,
gardening, and many other chores which don't require the use of freshwater. These
activities presently consume y liters of water every week per household and Arun
thinks through this campaign he can help cut down the total usage to ⌊y/2⌋.

Assuming x liters of water every week per household is consumed at chores where
using freshwater is mandatory and a total of C liters of water is available for the
entire Talentland having H households for a week, find whether all the households
can now have sufficient water to meet their requirements

Input:

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, four integers H,x,y,C.

Output:

Print a single line containing the string "YES" if it is possible to meet the
requirement of all the households in Talentland or "NO" if it is impossible
(without quotes).

You may print each character of each string in uppercase or lowercase (for example,
the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
3 ,3 1 1 3 ,1 1 1 2 ,2 1 1 1
Output:
YES YES NO

Testcase:2[Open Testcase]
Inputs:
2 ,2 1 4 5 ,3 5 2 1
Output:
NO NO

Testcase:3[Open Testcase]
Inputs:
2 ,2 2 1 4 ,3 4 5 6
Output:
YES NO

code->

#include<iostream>

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

int H,x,y,C,t,i;
cin>>H>>x>>y>>C;

i=y/2;

t= H*(x + i);

if(t>C)

cout<<"No"<<endl;

else

cout<<"Yes"<<endl;

return 0;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

39) The Preparations

Amit has an exam which will start exactly M minutes from now. However, instead of
preparing for his exam, Amit started watching Season-1 of Superchef. Season-1 has N
episodes, and the duration of each episode is K minutes.

Will Amit be able to finish watching Season-1 strictly before the exam starts?

Note: Please read the explanations of the sample test cases carefully.

Input Format

The first line contains an integer T denoting the number of test cases. T test
cases then follow.
The first and only line of each test case contains 3 space separated integers M, N
and K.

Output Format

For each test case, output on one line YES if it is possible to finish Season-1
strictly before the exam starts, or NO if it is not possible to do so.

Output is case insensitive, which means that "yes", "Yes", "YEs", "no", "nO" - all
such strings will be acceptable.

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
3 ,10 1 10 ,25 2 10 ,15 2 10
Output:
NO YES NO

Testcase:2[Open Testcase]
Inputs:
2 ,3 1 2 ,4 5 6
Output:
YES NO

Testcase:3[Open Testcase]
Inputs:
3 ,6 15 31 ,15 20 50 ,25 2 11
Output:
NO NO YES

code->

#include <bits/stdc++.h>

using namespace std;

int main() {

int t;
cin>>t;

while(t--)

int a,b,c;

cin>>a>>b>>c;

int ans=b*c;

if(a>ans)

cout<<"YES"<<endl;

else

cout<<"NO"<<endl;

}
return 0;

***********************************************************************************
*************************************************************************

40) Cars and Bikes

Sam opened a company which manufactures cars and bikes. Each car requires 4 tyres
while each bike requires 2 tyres. Sam has a total of N tyres (N is even). He wants
to manufacture maximum number of cars from these tyres and then manufacture bikes
from the remaining tyres.

Sam's friend went to Sam to purchase a bike. If Sam's company has manufactured even
a single bike then Sam's friend will be able to purchase it.

Determine whether he will be able to purchase the bike or not

Input Format

The first line contains an integer T denoting the number of test cases. The T test
cases then follow.

The first line of each test case contains an integer N denoting the number of
tyres.

Output Format

For each test case, output YES or NO depending on whether Sam's friend will be able
to purchase the bike or not. Output is case insensitive.

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
3 ,8 ,2 ,6
Output:
NO YES YES

Testcase:2[Open Testcase]
Inputs:
2 ,7 ,10
Output:
YES YES

Testcase:3[Open Testcase]
Inputs:
2 ,4 ,9
Output:
NO YES

code->

#include <iostream>

using namespace std;

int main() {

int t;

cin>>t;

while(t--)

int a;

cin>>a;

if(a%4==0)

std::cout << "no" << std::endl;

}
else{

cout<<"yes"<<endl;

// your code goes here

return 0;

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

41) Remove Element

You are given an array A=[A1,A2,…,AN] consisting of N positive integers.

You are also given a constant K, using which you can perform the following
operation on A:

Choose two distinct indices i and j such that Ai+Aj≤K, and remove either Ai or Aj
from A.

Is it possible to obtain an array consisting of only one element using several


(possibly, zero) such operations?

Input Format

The first line of input contains a single integer T, denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains two space-separated integers N and K.

The second line contains N space-separated integers A1,A2,…,AN.

Output Format

For each test case, print "YES" if it is possible to obtain an array consisting of
only one element using the given operation, otherwise print "NO".

Constraints
1≤T≤103

1≤N≤105

1≤Ai,K≤109

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
1 ,1 3 ,1
Output:
YES

Testcase:2[Open Testcase]
Inputs:
1 ,3 3 ,2 2 2
Output:
NO

Testcase:3[Open Testcase]
Inputs:
1 ,4 7 ,1 4 3 5
Output:
YES

code->

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {

int t;

cin>>t;
while(t--){

ll n,k;

cin>>n>>k;

vector<ll>arr;

for(int i=0;i<n;i++){

ll a;

cin>>a;

arr.push_back(a);

sort(arr.begin(),arr.end());

(arr[0]+arr[n-1]<=k || n == 1)?cout<<"YES\n" : cout<<"NO\n";

return 0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42) Fit to Play

Who's interested in football?

Adam has been one of the top players for his football club for the last few years.
But unfortunately, he got injured during a game a few months back and has been out
of play ever since.

He's got proper treatment and is eager to go out and play for his team again.
Before doing that, he has to prove to his fitness to the coach and manager of the
team. Adam has been playing practice matches for the past few days. He's played N
practice matches in all.

He wants to convince the coach and the manager that he's improved over time and
that his injury no longer affects his game. To increase his chances of getting back
into the team, he's decided to show them stats of any 2 of his practice games. The
coach and manager will look into the goals scored in both the games and see how
much he's improved. If the number of goals scored in the 2nd game(the game which
took place later) is greater than that in 1st, then he has a chance of getting in.
Tell Adam what is the maximum improvement in terms of goal difference that he can
show to maximize his chances of getting into the team. If he hasn't improved over
time, he's not fit to play. Scoring equal number of goals in 2 matches will not be
considered an improvement. Also, he will be declared unfit if he doesn't have
enough matches to show an improvement.

Input:

The first line of the input contains a single integer T, the number of test cases.
Each test case begins with a single integer N, the number of practice matches Adam
has played.

The next line contains N integers. The ith integer, gi, on this line represents the
number of goals Adam scored in his ith practice match. The matches are given in
chronological order i.e. j > i means match number j took place after match number
i.

Output:

For each test case output a single line containing the maximum goal difference that
Adam can show to his coach and manager. If he's not fit yet, print "UNFIT".

Constraints:

1<=T<=10

1<=N<=100000

0<=gi<=1000000

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.
Testcase:1[Open Testcase]
Inputs:
1 ,6 ,3 7 1 4 2 4
Output:
4

Testcase:2[Open Testcase]
Inputs:
1 ,5 ,5 4 3 2 1
Output:
UNFIT

Testcase:3[Open Testcase]
Inputs:
1 ,5 ,4 3 2 2 3
Output:
1

code->

#include<bits/stdc++.h>

using namespace std;

int main()

int t;

cin>>t;

while(t--){

int n;

cin>>n;
vector<int> v1(n);

for(int i=0;i<n;i++)

cin>>v1[i];

int mini=v1[0];

int diff=0;

for(int i=1;i<n;i++){

if(v1[i]-mini>diff)

diff=v1[i]-mini;

mini=min(mini,v1[i]);

if(diff<=0)

cout<<"UNFIT"<<endl;

else
cout<<diff<<endl;

return 0;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

43)Different courses

There are n courses in a university being offered. These courses are numbered from
1 to n in the increasing order of their difficulty. For each course, you can have
some courses as prerequisites. The prerequisite courses for a course should be of
lower difficulty than it. You are given an array a of size n, where ai denotes that
there should be at least ai prerequisite courses for i-th course.

The university wants to estimate the efficiency of the allocation of prerequisites


of courses by maximizing the number of courses that are not prerequisites for any
other course. Find out what's the maximum such number of courses possible. It is
guaranteed that ai < i, thus making sure that it is possible to allocate the
prerequisites for each of the course.

Input

The first line of the input contains an integer T denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains an integer n.

The second line of each test case contains n space separated integers denoting
array a.

Output

For each test case, output a single line containing an integer corresponding to the
maximum number of possible courses which are not prerequisite for any other course.

Constraints

1 ≤ T ≤ 10

1 ≤ n ≤ 105

0 ≤ ai < i

Instructions:
1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
1 ,3 ,0 1 1
Output:
2

Testcase:2[Open Testcase]
Inputs:
1 ,3 ,0 1 2
Output:
1
:
Testcase:3[Open Testcase]
Inputs:
2 ,3 ,3 4 0
Output:
-1

code->

#include <bits/stdc++.h>

using namespace std;

void Solve()

int n;

cin >> n;

vector<int> v(n);

for (int i = 0; i < n; i++)


cin >> v[i];

vector<bool> vect(n, false);

int max=0;

for (int i = 1; i < n; i++)

int val = v[i];

if(val>max){

for (int j = max; j < val; j++)

vect[j] = true;

max=val;

int cnt = 0;
for (int i = 0; i < n; i++)

if (vect[i] == false)

cnt++;

cout << cnt << endl;

int main()

int t;

cin >> t;

while (t--)
{

Solve();

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

44) Average Flex

There are N students in a class, where the i-th student has a score of Ai.

The i-th student will boast if and only if the number of students scoring less than
or equal Ai is greater than the number of students scoring greater than Ai.

Find the number of students who will boast.

Input Format

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

The first line of each test case contains a single integer N - the number of
students.

The second line of each test case contains N integers A1,A2,…,AN - the scores of
the students.

Output Format

For each test case, output in a single line the number of students who will boast.

Constraints

1≤T≤1000

1≤N≤100

0≤Ai≤100

Testcase:1[Open Testcase]
Inputs:
1 ,3 ,100 100 100
Output:
3

Testcase:2[Open Testcase]
Inputs:
1 ,3 ,2 1 3
Output:
2

Testcase:3[Open Testcase]
Inputs:
1 ,4 ,30 1 30 30
Output:
3

code->

#include<bits/stdc++.h>

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

int n;

cin>>n;

int a[n];

for(int i=0;i<n;i++) cin>>a[i];

sort(a,a+n);

int ans=(n+1)/2;
for(int i=n/2-1;i>=0;i--){

if(a[i]!=a[i+1]) break;

else ans++;

cout<<ans<<endl;

###################################################################################
#########################################################################

45) Angel and Walking on the rectangle

Angel likes rectangles. Among all possible rectangles, she loves rectangles that
can be drawn like a grid, such that they have N rows and M columns. Grids are
common in Byteland. Hence, Angel has drawn such a rectangle and plans on moving
around in it.

The rows of the rectangle are labeled from 1 to N from top to bottom. The columns
of the rectangle are labeled form 1 to M from left to right. Thus, the cell in the
top left can be denoted by (1,1). The 5th cell from the left in the 4th row form
the top can be denoted by (4,5). The bottom right cell can be denoted as (N,M).

Angel wants to move from the cell in the top left to the cell in the bottom right.
In each move, Angel may only move one cell right, or one cell down. Also, Angel is
not allowed to move to any cell outside the boundary of the rectangle.

Of course, there are many ways for Angel to move from (1,1) to (N,M). Angel has a
curious sport. While going from (1,1) to (N,M), he drops a stone on each of the
cells he steps on, except the cells (1,1) and (N,M). Also, Angel repeats this game
exactly K times.

Let us say he moved from (1,1) to (N,M), exactly K times. At the end of all the K
journeys, let the number of stones, in the cell with the maximum number of stones,
be equal to S. Angel wants to know what is the smallest possible value for S.

Input

The first line contains single integer T, the number of test cases. Each of the
next T lines contains 3 integers N, M and K, respectively.

Output

For each test case, output the smallest value possible for S, if the Angel chooses
the K paths smartly.

Constraints

1 ≤ T ≤ 100

1 ≤ N, M, K ≤ 70

Instructions:

1. Strictly follow the input and output format.

2. Extra spaces in the input and output should be avoided and case sensitive nature
of input and output should be maintained if necessary.

3. Select appropriate language from given options and submit the code for
evaluation after completion.

Testcase:1[Open Testcase]
Inputs:
1 ,2 2 1
Output:
1

Testcase:2[Open Testcase]
Inputs:
1 ,3 3 2
Output:
1

Testcase:3[Open Testcase]
Inputs:
1 ,1 5 12
Output:
12

code->

Test Case 1: Angel may choose any way. The maximum value on any cell would be 1.

Test Case 2: If Angel selects two paths that have a common cell, such as

(1,1)->(1,2)->(2,2)->(3,2)->(3,3)

(1,1)->(2,1)->(2,2)->(3,2)->(3,3)
Then the value of S will be equal to 2, since the number of stones in (2,2) and
(3,2) is equal to 2. But, if Angel selects two paths which do not have any common
cells, such as

(1,1)->(1,2)->(1,3)->(2,3)->(3,3)

(1,1)->(2,1)->(3,1)->(3,2)->(3,3)

Then the value of S will be equal to 1.

#include <iostream>

using namespace std;

int main() {

int t;

cin>>t;

while(t--){

int n,m,k;

cin>>n>>m>>k;

if((n+m)<=3){
cout<<0<<endl;

else if(n==1 || m==1){

cout<<k<<endl;

else {

if(k%2==0){

cout<<k/2<<endl;

else{

cout<<k/2+1<<endl;

}
return 0;

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

46)Write a program to print Floyd’s triangle

Description

Get the number of rows as input and print the following pattern

Testcase:1[Open Testcase]
Inputs:
4
Output:
1 2 3 4 5 6 7 8 9 10 11

code->

#include <iostream>

using namespace std;

int main() {

int i, j, n, Num =1;

cout<<"Enter the number of rows: ";

cin>>n;

for(i=1; i<=n; i++)

{
for(j=1; j<=i; j++)

cout<<Num++ <<" ";

cout<<"\n";

return 0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

47) Olympics Ranking

In Olympics, the countries are ranked by the total number of medals won. You are
given six integers G1, S1, B1, and G2, S2, B2, the number of golds, silver and
bronze medals won by two different countries respectively. Determine which country
is ranked better on the leaderboard. It is guaranteed that there will not be a tie
between the two countries.

Input Format

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first and only line of each test case contains six space-separated integers G1,
S1, B1, and G2, S2, B2.

Output Format

For each test case, print "1" if the first country is ranked better or "2"
otherwise. Output the answer without quotes.

Testcase:1[Open Testcase]
Inputs:
1 ,10 20 30 0 29 30
Output:
1

Testcase:2[Open Testcase]
Inputs:
1 ,0 0 0 0 0 1
Output:
2
Testcase:3[Open Testcase]
Inputs:
1 ,1 1 1 0 0 0
Output:
1

code->

#include <iostream>

using namespace std;

class olympics{

int g1, s1, b1, g2, s2, b2;

public:

void input(){

cin>>g1>>s1>>b1>>g2>>s2>>b2;

int calculate(){

if((g1+s1+b1) > (g2+s2+b2)){

return 1;
}

else {

return 2;

};

int main() {

int t;

olympics o;

cin>>t;

while(t--){

o.input();
cout<<o.calculate()<<endl;

return 0;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

48) Puppy and Sum

Yesterday, puppy Tom learned a magically efficient method to find the sum of the
integers from 1 to N. He denotes it as sum(N). But today, as a true explorer, he
defined his own new function: sum(D, N), which means the operation sum applied D
times: the first time to N, and each subsequent time to the result of the previous
operation.

For example, if D = 2 and N = 3, then sum(2, 3) equals to sum(sum(3)) = sum(1 + 2 +


3) = sum(6) = 21.

Tom wants to calculate some values of the sum(D, N) function. Will you help him
with that?

Input

The first line contains a single integer T, the number of test cases. Each test
case is described by a single line containing two integers D and N.

Output

For each testcase, output one integer on a separate line.

Testcase:1[Open Testcase]
Inputs:
1 ,1 4
Output:
10

Testcase:2[Open Testcase]
Inputs:
1 ,2 3
Output:
21

Testcase:3[Open Testcase]
Inputs:
1 ,2 4
Output:
55

code->

#include <iostream>

using namespace std;

int sum,l;

int funcn(int d,int n)

sum=0,l=d;

for(int i=1;i<=n;i++)

sum+=i;

l--;

while(l!=0)

funcn(l,sum);
}

return (sum);

int main()

int T,D,N,val;

cin>>T;

while(T!=0)

cin>>D>>N;

val=funcn(D,N);
cout<<"\n "<<val;

T--;

return 0;

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

49) Shoe Fit

You have three shoes of the same size lying around. Each shoe is either a left shoe
(represented using 0) or a right shoe (represented using 1). Given A, B, C,
representing the information for each shoe, find out whether you can go out now,
wearing one left shoe and one right shoe.

Input Format

The first line contains an integer T, the number of test cases. Then the test cases
follow.

Each test case contains a single line of input, three integers A, B, C.

Output Format

For each test case, output in a single line the answer: 1 if it's possible to go
out with a pair of shoes and 0 if not

Testcase:1[Open Testcase]
Inputs:
1 ,0 0 0
Output:
0

Testcase:2[Open Testcase]
Inputs:
1 ,0 1 1
Output:
1

Testcase:3[Open Testcase]
Inputs:
1 ,1 0 1
Output:
1
code->

#include <iostream>

using namespace std;

class shoe{

int size[3];

public:

void input(){

for(int i = 0; i < 3; i++){

cin>>size[i];

int find(){

if(size[0] == 0 && size[1] == 0 && size[2] == 0){

return 0;

}
else if(size[0] == 1 && size[1] == 1 && size[2] == 1){

return 0;

else {

return 1;

};

int main() {

int t;

cin>>t;
shoe s;

while(t--){

s.input();

cout<<s.find()<<endl;

return 0;

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

50) Marathon

Magicland is holding a virtual marathon for the categories 10 km, 21 km and 42 km


having prizes A,B,C (A<B<C) respectively to promote physical fitness. In order to
claim the prize in a particular category the person must cover the total distance
for that category within D days. Also a single person cannot apply in multiple
categories.

Given the maximum distance d km that Arun can cover in a single day, find the
maximum prize that Arun can win at the end of D days. If Arun can't win any prize,
print 0

Input

The first line contains an integer T, the number of test cases. Then the test cases
follow.

Each test case contains a single line of input, five integers D,d,A,B,C.

Output

For each test case, output in a single line the answer to the problem.

Testcase:1[Open Testcase]
Inputs:
1 ,1 1 1 2 3
Output:
0
Testcase:2[Open Testcase]
Inputs:
1 ,10 1 1 2 3
Output:
1

Testcase:3[Open Testcase]
Inputs:
1 ,10 3 1 2 3
Output:
2

code->

#include <iostream>

using namespace std;

int main(){

int T,D,d,A,B,C,sum;

cin>>T;

while(T!=0)

cin>>D>>d>>A>>B>>C;

sum=D*d;

if(sum<10)

cout<<"\n 0";

else if(sum>=10&&sum<21)
cout<<"\n "<<A;

else if(sum>=21&&sum<42)

cout<<"\n "<<B;

else

cout<<"\n "<<C;

T--;

return 0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

51) Amit in Vaccination Queue

There are N people in the vaccination queue, Amit is standing on the Pth position
from the front of the queue. It takes X minutes to vaccinate a child and Y minutes
to vaccinate an elderly person. Assume Amit is an elderly person.

You are given a binary array A1,A2,…,AN of length N, where Ai=1 denotes there is an
elderly person standing on the ith position of the queue, Ai=0 denotes there is a
child standing on the ith position of the queue. You are also given the three
integers P,X,Y. Find the number of minutes after which Amit's vaccination will be
completed.

Input Format

First line will contain T, number of testcases. Then the testcases follow.

The first line of each test case contains four space-separated integers N,P,X,Y.
The second line of each test case contains N space-separated integer A1,A2,…,AN.

Output Format

For each testcase, output in a single line the number of minutes after which Amit's
vaccination will be completed.

Testcase:1[Open Testcase]
Inputs:
1 ,4 2 3 2 ,0 1 0 1
Output:
5

Testcase:2[Open Testcase]
Inputs:
1 ,3 1 2 3 ,1 0 1
Output:
3

Testcase:3[Open Testcase]
Inputs:
1 ,3 3 2 2 ,1 1 1
Output:
6

code->

#include <iostream>

using namespace std;

int main() {

int t;

cin>>t;

while(t--)

int n,p,x,y,min = 0;
cin>>n>>p>>x>>y;

int arr[n];

for(int i = 0; i<n; i++)

cin>>arr[i];

for(int j = 0; j<p; j++)

if(arr[j] == 1)

min = min+y;

else{

min = min+x;
}

cout<<min<<endl;

return 0;

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

52) Hiring Test

A company conducted a coding test to hire candidates. N candidates appeared for the
test, and each of them faced M problems. Each problem was either unsolved by a
candidate (denoted by 'U'), solved partially (denoted by 'P'), or solved completely
(denoted by 'F').

To pass the test, each candidate needs to either solve X or more problems
completely, or solve (X−1) problems completely, and Y or more problems partially.

Given the above specifications as input, print a line containing N integers. The
ith integer should be 1 if the ith candidate has passed the test, else it should be
0.

Input:

The first line of the input contains an integer T, denoting the number of test
cases.

The first line of each test case contains two space-separated integers, N and M,
denoting the number of candidates who appeared for the test, and the number of
problems in the test, respectively.

The second line of each test case contains two space-separated integers, X and Y,
as described above, respectively.

The next N lines contain M characters each. The jth character of the ith line
denotes the result of the ith candidate in the jth problem. 'F' denotes that the
problem was solved completely, 'P' denotes partial solve, and 'U' denotes that the
problem was not solved by the candidate.
Output:

For each test case, print a single line containing N integers. The ith integer
denotes the result of the ith candidate. 1 denotes that the candidate passed the
test, while 0 denotes that he/she failed the test.

Testcase:1[Open Testcase]
Inputs:
1 ,4 5 ,3 2 ,FUFFP ,PFPFU ,UPFFU ,PPPFP
Output:
1100

Testcase:2[Open Testcase]
Inputs:
1 ,3 4 ,1 3 ,PUPP ,UUUU ,UFUU
Output:
101

Testcase:3[Open Testcase]
Inputs:
1 ,1 3 ,2 2 ,PPP
Output:
0

code->

#include <iostream>

using namespace std;

int main() {

int t; cin>>t;

while(t--) {

int n,m,x,y; cin>>n>>m>>x>>y;

int ans[n];

for(int i=0; i<n; i++) {

int f=0,p=0,u=0;
for(int j=0; j<m; j++) {

char a; cin>>a;

if(a=='F') f++;

if(a=='P') p++;

if(a=='U') u++;

//cout<<f<<" "<<p<<" "<<u<<endl;

if((f>=x) ||(f+1==x && p>=y)) ans[i]=1;

else ans[i]=0;

for(int e:ans) cout<<e;

cout<<"\n";

return 0;
}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

53) Phone Prices

Amit wants to buy a new phone, but he is not willing to spend a lot of money.
Instead, he checks the price of his chosen model everyday and waits for the price
to drop to an acceptable value. So far, he has observed the price for N days
(numbers 1 through N); for each valid i, the price on the i-th day was Pi dollars.

On each day, Amit considers the price of the phone to be good if it is strictly
smaller than all the prices he has observed during the previous five days. If there
is no record of the price on some of the previous five days (because Amit has not
started checking the price on that day yet), then Amit simply ignores that previous
day ― we could say that he considers the price on that day to be infinite.

Now, Amit is wondering ― on how many days has he considered the price to be good?
Find the number of these days.

Input

The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.

The first line of each test case contains a single integer N.

The second line contains N space-separated integers P1,P2,…,PN.

Output

For each test case, print a single line containing one integer ? the number of days
with a good price.

Constraints

1≤T≤100

7≤N≤100

350≤Pi≤750 for each valid i

Testcase:1[Open Testcase]
Inputs:
1 ,7 ,375 750 723 662 647 656 619
Output:
2

Testcase:2[Open Testcase]
Inputs:
1 ,6 ,375 455 360 545 720 440
Output:
2

Testcase:3[Open Testcase]
Inputs:
1 ,10 ,380 380 350 355 351 640 645 420 525 600
Output:
2

code->

#include <iostream>

using namespace std;

int main() {

int t;cin>>t;

while(t--){

int n,a1,a2;cin>>n;

int arr[n];

for(int i=0;i<n;i++){

cin>>arr[i];

int count=1;

for(int i=1;i<n;i++){

a1=max(i-5,0);
a2=max(i-1,0);

int c=0;

for(int j=a1;j<=a2;j++){

if(arr[i]<arr[j]){

c+=1;

if(c==(a2-a1+1)){

count+=1;

cout<<count<<endl;

return 0;
}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

54) Magical Planks

Smitha is a girl from a small town, who has been given a task by her father. She
has N wooden planks, numbered from 1 to N, which are colored either black or white.

Her task is to color all planks the same color! But there is some magic in the
winds of her small town. Whenever she colors the ith ( plank which has the color Si
) to a color P then following events happen:

if 2≤i≤N and Si=Si−1, then color of (i−1)th plank changes to P.

if 1≤i≤N−1 and Si=Si+1, then color of (i+1)th plank changes to P.

Now this process continues for the newly colored planks also. If none of the
neighbors have same color, then nothing happens to the neighbors.

Suppose Smitha has planks which have their coloring : BBWWWB If Smitha colors the
fourth plank( whose color is W ) to color B, then the finally the planks would be
colored as following:

BBBBBB

Smitha can choose any one of the N planks and change its color as many times as she
wants. Determine the minimum number of times Smitha has to paint a plank such that
all planks get the same color at the end.

Input Format

First line will contain T, number of testcases. Then the testcases follow.

The first line of each test case consists of an integer N the number of planks

Second line of each test case consists of a string S of size N,where the ith
character denotes the color of plank i

Output Format

For each testcase, output a single integer denoting the minimum number of times
Smitha has to paint a single plank such that all planks get the same color at the
end.

Constraints

1≤T≤105

1≤N≤105

S consists only of characters B and W


The sum of N over all cases doesn't exceed 105.

Testcase:1[Open Testcase]
Inputs:
4 ,6 ,BBWWWB ,5 ,WWBWB ,2 ,BB ,9 ,WWBBBBBWW
Output:
1 2 0 1

Testcase:2[Open Testcase]
Inputs:
3 ,4 ,WWWW ,5 ,WBWBW ,1 ,B
Output:
0 2 0

Testcase:3[Open Testcase]
Inputs:
1 ,5 ,BBWBW
Output:
2

code->

#include<iostream>

using namespace std;

int check(string str,int n,char curr){

int count = 0;

if(str[0] == curr)

count++;

for(int i=1;i<n;i++){

if(str[i] == curr && str[i-1] != curr)

count++;

return count;

int main()

int t,n;

cin >> t;

while(t--){
string str;

cin >> n >> str;

cout << min(check(str,n,'W'),check(str,n,'B')) << endl;

return 0;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

55) Password

Amit is planning to setup a secure password for his TalentBattle account. For a
password to be secure the following conditions should be satisfied:

1) Password must contain at least one lower case letter [a−z];

2) Password must contain at least one upper case letter [A−Z] strictly inside, i.e.
not as the first or the last character;

3) Password must contain at least one digit [0−9] strictly inside;

4) Password must contain at least one special character from the set { '@', '#',
'%', '&', '?' } strictly inside;

5) Password must be at least 10 characters in length, but it can be longer.

Amit has generated several strings and now wants you to check whether the passwords
are secure based on the above criteria. Please help Amit in doing so.

Input

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, string S.

Output

For each testcase, output in a single line "YES" if the password is secure and "NO"
if it is not.

Constraints

1≤|S|≤20

All the characters in S are one of the following: lower case letters [a−z], upper
case letters [A−Z], digits [0−9], special characters from the set { '@', '#', '%',
'&', '?' }

Sum of length of strings over all tests is atmost 106

Testcase:1[Open Testcase]
Inputs:
3 ,#cookOff#P1 ,U@code4CHEFINA ,gR3@tPWD
Output:
NO YES NO

Testcase:2[Open Testcase]
Inputs:
3 ,#@%? ,abCD@1 ,1234
Output:
NO NO NO

Testcase:3[Open Testcase]
Inputs:
1 ,Localiz@ti0n
Output:
YES

code->

#include <bits/stdc++.h>

using namespace std;

int main() {

int t; cin >> t;

while(t--)

string s; cin >> s;

bool num = false;

bool Sletter = false;

bool Bletter = false;

bool symbol = false;

if(s.size() >= 10)

for(int i=0; i<s.size(); i++)

if(s[i]>=97 && s[i]<=122)

Sletter = true;

}
else if(s[i]>=65 && s[i]<=90 && !Bletter)

if(i>0 && i<s.size()-1)

Bletter = true;

else if(s[i]>=48 && s[i]<=57 && !num)

if(i>0 && i<s.size()-1)

num = true;

else if(s[i]=='@' || s[i]=='#' || s[i]=='%' || s[i]=='&' ||


s[i]=='?')

if(i>0 && i<s.size()-1)

symbol = true;

if(num==true && symbol==true && Bletter==true && Sletter==true)

cout << "YES" << endl;

else

{
cout << "NO" << endl;

return 0;

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

56) TalentBattle Travel Routes

Anoop likes to travel very much. He plans some travel routes and wants to know
their lengths. He hired you to make these calculations. But be careful, some of the
routes are incorrect. There may be some misspelling in city names or there will be
no road between some two consecutive cities in the route. Also note that Anoop
hates to visit the same city twice during his travel. Even the last city should
differ from the first. Two consecutive cities in the route should also be
different. So you need to check these conditions for the given routes too.

You will be given the list of all cities and all roads between them with their
lengths. All roads are one-way. Also you will be given the list of all travel
routes that Anoop plans. For each route you should check whether it is correct and
find its length in this case.

Input

The first line contains positive integer N, the number of cities. The second line
contains space separated list of N strings, city names. All city names are
distinct.

The third line contains non-negative integer M, the number of available roads. Each
of the next M lines describes one road and contains names C1 and C2 of two cities
followed by the positive integer D, the length of the one-way road that connects C1
with C2. It is guaranteed that C1 and C2 will be correct names of two different
cities from the list of N cities given in the second line of the input file. For
each pair of different cities there is at most one road in each direction and each
road will be described exactly once in the input file.

Next line contains positive integer T, the number of travel routes planned by the
Anoop. Each of the next T lines contains positive integer K followed by K strings,
names of cities of the current route. Cities are given in order in which Anoop will
visit them during his travel.

All strings in the input file composed only of lowercase, uppercase letters of the
English alphabet and hyphens. Each string is non-empty and has length at most 20.
If some line of the input file contains more then one element than consecutive
elements of this line are separated by exactly one space. Each line of the input
file has no leading or trailing spaces.

Output

For each travel route from the input file output a single line containing word
ERROR if the route is incorrect and its length otherwise.
Constraints

1 <= N <= 50

0 <= M <= N * (N - 1)

1 <= D <= 20000

1 <= T <= 50

1 <= K <= 50

1 <= length of each string <= 20

Testcase:1[Open Testcase]
Inputs:
5 ,Donetsk Kiev New-York Miami Hollywood ,9 ,Donetsk Kiev 560 ,Kiev New-York
7507 ,New-York Miami 1764 ,Miami Hollywood 28 ,Hollywood Miami 30 ,Miami New-York
1764 ,Kiev Donetsk 550 ,Hollywood New-York 1736 ,New-York Hollywood 1738 ,5 ,5
Donetsk Kiev New-York Miami Hollywood ,5 Hollywood Miami New-York Kiev Donetsk ,3
Donetsk Kiev Donetsk ,2 Kyiv New-York ,3 New-York Hollywood Miami
Output:
9859 ERROR ERROR ERROR 1768

Testcase:2[Open Testcase]
Inputs:
5 ,Donetsk Kiev New-York Miami Hollywood ,9 ,Donetsk Kiev 560 ,Kiev New-York
7507 ,New-York Miami 1764 ,Miami Hollywood 28 ,Hollywood Miami 30 ,Miami New-York
1764 ,Kiev Donetsk 550 ,Hollywood New-York 1736 ,New-York Hollywood 1738 ,5 ,2 New-
York Miami ,3 Hollywood New-York Miami ,4 Donetsk Kiev Miami Hollywood ,2 Donetsk
Hollywood ,1 Donetsk
Output:
1764 3500 ERROR ERROR 0

Testcase:3[Open Testcase]
Inputs:
5 ,Donetsk Kiev New-York Miami Hollywood ,9 ,Donetsk Kiev 560 ,Kiev New-York
7507 ,New-York Miami 1764 ,Miami Hollywood 28 ,Hollywood Miami 30 ,Miami New-York
1764 ,Kiev Donetsk 550 ,Hollywood New-York 1736 ,New-York Hollywood 1738 ,3 ,2
Mumbai Deli ,6 Donetsk Kiev New-York Miami Hollywood New-York ,2 Miami Miami
Output:
ERROR ERROR ERROR

code->

#include <bits/stdc++.h>

using namespace std;

int main() {

int n,dist,m,t,k,x;cin>>n;
map<string,int>cities;

string s,s1,s2;

for(int i=0;i<n;i++){

cin>>s;

cities[s]=1;

cin>>m;

map<string,map<string,int>>routes;

while(m--){

cin>>s1>>s2>>dist;

routes[s1][s2]=dist;

cin>>t;
while(t--){

long long int dist=0,f=0;

cin>>k;

vector<string>v(k);

x=k;

map<string,int>check;

for(int i=0;i<k;i++){

cin>>v[i];

if(check[v[i]])

f=1;

else

check[v[i]]=1;

if(k==1 && cities[v[0]])

cout<<0<<endl;
else if(k==1)

cout<<"ERROR"<<endl;

else{

for(int i=0;i<k-1;i++){

if(routes[v[i]][v[i+1]])

dist+=routes[v[i]][v[i+1]];

else{

f=1;

break;

if(f==1)

cout<<"ERROR"<<endl;

else

cout<<dist<<endl;
}

return 0;

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

57) Correctness of Knight Move

Amit develops his own computer program for playing chess. He is at the very
beginning. At first he needs to write the module that will receive moves written by
the players and analyze it. The module will receive a string and it should report
at first whether this string represents the correct pair of cells on the chess
board (we call such strings correct) and then report whether it represents the
correct move depending on the situation on the chess board. Amit always has
troubles with analyzing knight moves. So at first he needs a test program that can
say whether a given string is correct and then whether it represents a correct
knight move (irregardless of the situation on the chess board). The cell on the
chessboard is represented as a string of two characters: first character is a
lowercase Latin letter from a to h and the second character is a digit from 1 to 8.
The string represents the correct pair of cells on the chess board if it composed
of 5 characters where first two characters represent the cell where chess figure
was, 3rd character is the dash "-" and the last two characters represent the
destination cell.

Input

The first line contains a single integer T <= 50000, the number of test cases. T
test cases follow. The only line of each test case contains a non-empty string
composed the characters with ASCII-codes from 32 to 126. The length of the string
is not greater than 10.

Output

For each test case, output a single line containing the word "Error" if the
corresponding string does not represent the correct pair of cells on the chess
board. Otherwise output "Yes" if this pair of cells represents the correct knight
move and "No" otherwise.

Testcase:1[Open Testcase]
Inputs:
1 ,a1-b3
Output:
Yes
Testcase:2[Open Testcase]
Inputs:
1 ,d2-h8
Output:
No

Testcase:3[Open Testcase]
Inputs:
2 ,a3 c4 ,ErrorError
Output:
Error Error

code->

#include<bits/stdc++.h>

#define ll long long int

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

void solve()

string s;

getline(cin,s);

if(s[0]>='a' && s[0]<='h' && s[1]>='1' && s[1]<='8' && s[2]=='-' && s[3]>='a'
&& s[3]<='h' && s[4]>='1' && s[4]<='8' && s.length()==5)

if(abs(s[0]-s[3])==2 && abs(s[1]-s[4])==1)


cout<<"Yes";

else if(abs(s[0]-s[3])==1 && abs(s[1]-s[4])==2)

cout<<"Yes";

else

cout<<"No";

else

cout<<"Error";

int main()

fastio

ll t;

cin>>t;

cin.ignore();
while(t--)

solve();

cout<<"\n";

return 0;

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

58) Digital clock

3:33

It's possible for all the digits displayed on a digital clock in the hours:minutes
format to be identical. The time shown above (3:33) is an example of such a
situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are
identical, but it is not a valid time on a usual digital clock.

The above example was for a usual 24-hour format digital clock. Let's consider a
more general clock, where an hour lasts M minutes and a day lasts H hours
(therefore, the clock can show any number of hours between 0 and H-1, inclusive,
and any number of minutes between 0 and M-1, inclusive). Both the hours and the
minutes are shown without leading zeroes in decimal notation and their separator
(e.g., ':') doesn't matter.

Can you tell how many minutes during a day will the digital clock have identical
digits displayed on it?

Input

The first line of the input contains an integer T - the number of test cases.
Each of the next T lines contains two space-separated integers H and M for one test
case.

Output

For each test case, output a single line corresponding to the answer of the
problem.

Constraints

1 ≤ T ≤ 50

1 ≤ H, M ≤ 100

Testcase:1[Open Testcase]
Inputs:
2 ,24 60 ,34 50
Output:
19 20

Testcase:2[Open Testcase]
Inputs:
1 ,10 11
Output:
10

Testcase:3[Open Testcase]
Inputs:
3 ,10 12 ,11 11 ,1 1
Output:
11 10 1

code->

#include<bits/stdc++.h>

using namespace std;

int main()

int tc;

cin>>tc;

while(tc--)
{

int n, m;

cin>>n>>m;

set<char> uq;

int count = 0;

for(int i = 0 ; i < n ; i++)

for(int j = 0 ; j < m ; j++)

string ans = to_string(i) + to_string(j);

for(int i = 0 ; i < ans.length() ; i++)

uq.insert(ans[i]);

}
if(uq.size() == 1)

count++;

uq.clear();

cout<<count<<endl;

You might also like