Posts

Two Teams - Find the Winner

  Two Teams - Find the Winner  PROBLEM STATEMENT : There are two teams A and B playing a game. The game consists of N rounds. The points scored by both teams in N rounds are passed as the input to the program. The winner of the game is declared based on the following conditions.  - The team that wins more rounds than the other team is the winner of the game.  - If both teams win the same number of rounds, the team with the most points wins the game.  - If both teams win the same number of rounds and have the same number of points, then the result of the last round is considered.  The program must print the output based on the following conditions.  - If team A wins the game, then print the string value "Team A".  - If team B wins the game, then print the string value "Team B".  - If the result is a tie, then print the string value "TIE".  Boundary Condition(s):   1 <= N <= 100  Input Format:   The first line contains...

Rearrange Integer Matrix - Alphabets

 Rearrange Integer Matrix - Alphabets  PROBLEM STATEMENT : The program must accept an integer matrix M1 and a character matrix M2 having the same size R*C as the input. The matrix M2 contains only lower case alphabets. The program must rearrange the integer matrix M1 based on the positions of the alphabets in M2 after sorting the alphabets. The integer value in M1 must be relocated to the original position (before sorting) of the alphabet in M2 in having the same position in the sorted matrix M2. If two or more alphabets are same, then the program must consider them in the order of their occurrence. Finally, the program must print the modified matrix M1 as the output.  Boundary Condition(s):  2 <= R, C <= 50  1 <= Matrix element value <= 1000  Input Format:  The first line contains R and C separated by a space.  The next R lines, each contains C integer values representing the integer matrix M1.  The next R lines from the (R+2)th ...

Zig-Zag Robots

 Zig-Zag Robots  PROBLEM STATEMENT : There are R robots in R rows (i.e., one robot in each row). There are two types of robots which are given below.  Type 1: The robots start moving towards the East. Once it reaches the end of the row, it again starts moving towards the West. Similarly, the type 1 robots move in the direction East-West alternatively.  Type 2: The robots start moving towards the West. Once it reaches the end of the row, it again starts moving towards the East. Similarly, the type 2 robots move in the direction West-East alternatively. The speed of each robot is 1 meter per second. The length of each row is C meters. The initial state of the robots is passed as the input. The program must print the state of the robots after T seconds as the output. The value of T is also passed as the input.  Boundary Condition(s):   2 <= R, C <= 50  1 <= T <= 10^4  Input Format:   The first line contains R and C separated by a s...

Left Number Twice Right

 Left Number Twice Right  PROBLEM STATEMENT : A set of N numbers (separated by one or more spaces) is passed as input to the program. The program must identify the count of numbers C where the number on the left is twice the number on the right.  Boundary Conditions:   3 <= N <= 50  The value of the numbers can be from -99999999 to 99999999  Input Format: The first line will contain the N numbers separated by one or more spaces.  Output Format: The first line contains the value of C.  Example Input/Output 1:   Input: 10 20 5 40 15 -2 -30 -1 60  Output: 2 Explanation: The numbers meeting the criteria are 20, -30  Example Input/Output 2:  Input: 5 90 10 2 5 -4 10 6 5 3  Output: 3 Explanation: The numbers meeting the criteria are 2, 6, 5 SOLUTION : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int main() { int a[50],n=-1,i,cnt=0; while(scanf("%d",&a[++n...

Largest & Smallest Digits Difference

Largest & Smallest Digits Difference  PROBLEM STATEMENT : A number N is passed as the input. The program must print the difference between the largest and the smallest digits in the number.  Input Format:  The first line will contain the number N.  Boundary Conditions: 10 <= N <= 99999999  Output Format: The difference between the largest and the smallest digits in the number N.  Example Input/Output 1:  Input: 2501  Output: 5  Explanation: The largest digit is 5. The smallest digit is 0. The difference is 5-0 = 5 is printed as the output.  Example Input/Output 2:  Input:  22  Output: 0  Explanation: Both the largest and the smallest digit is 2. Hence the difference 2-2 = 0 is printed as the output. SOLUTION : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int main() { int n,min,max,u; scanf("%d",&n); min=n%10; max=n%10; while(n) ...

Submatrices - Diagonal Elements Sum :

Submatrices - Diagonal Elements Sum :  PROBLEM STATEMENT :   The program must accept an integer matrix M of size R*C and an integer N as the input. The program must print the sum of diagonal elements of all the N*N non-overlapping submatrices in M as the output.  Note: The value of N is always greater than 1 and less than or equal to the minimum value between R and C.  Boundary Condition(s):  2 <= R, C <= 50  0 <= Matrix element value <= 1000  Input Format:  The first line contains R and C separated by a space.  The next R lines, each contains C integer values separated by a space.  The (R+2)th line contains N.  Output Format:   The first line contains the integer values representing the sum of diagonal elements of all N*N non-overlapping submatrices in M.  Example Input/Output 1:  Input:  5 6  6 3 6 3 2 1 4 5 7 1 3 8 6 9 8 4 3 2  4 1 8 8 9 1  8 1 5 7 9 0  3  Output:  31...

Filling Holes with Wooden Sticks

Image
Filling Holes with Wooden Sticks  PROBLEM STATEMENT : SOLUTIONS : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int main() { int r,c,i,j,n,k,flag=0; scanf("%d %d\n",&r,&c); char ch[r][c],s[2]; for(i=0;i<r;++i) { for(j=0;j<c;++j) { scanf("%s",s); ch[i][j]=s[0]; } } scanf("%d\n",&n); int x[n]; for(i=0;i<n;++i) { scanf("%d ",&x[i]); } for(j=0;j<c;++j) { i=0; while(i<r&&ch[i][j]=='*') i+=1; for(k=0;k<n;++k) { if(x[k]==i) { x[k]=-1; k=-1; break; } } if(k==-1) { i-=1; while(i>=0) { ch[i][j]='#'; i-=1; } } } ...