Constellation - CodeVita 9 | Zonal Round
Parallelograms | Code Vita 2018 | round 1
Problem Description
Constraints
Input Format
Output
Explanation
Program:
#include<stdio.h>
int pairfound(int angle[],int i,int n)
{
int j;
for(j=i+1;j<n;j++)
{
if(angle[i]==angle[j])
return 1;
}
return 0;
}
int main()
{
int n,i,count=0,pllgm,ang;
scanf("%d",&n);
int angle[n];
for(i=0;i<n;i++)
{
scanf("%d,",&ang);
if(ang>=-89&&ang<=90)
angle[i]=ang;
}
for(i=0;i<n;i++)
{
if(pairfound(angle,i,n)==1)
{
count++;
}
}
pllgm=(count-1)*count/2;
printf("%d",pllgm);
return 0;
}
Output
6
20,20,-20,-20,50,50
3
You can also try it in online IDE: https://ide.geeksforgeeks.org/vVEgz35Wso
Your comments and feedback are welcomed! You can contact me if you have any doubts! Cheers!
Related Links: Reverse Gear
Super Ascii - Code Vita 2014 | round 2
Super Ascii
Problem Decription:
In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.
Your task is to find out whether the given string is a super ascii string or not.
Input Format:
First line contains number of test cases T, followed by T lines, each containing a string "S".
Output Format:
For each test case print "Yes" if the String "S" is super ascii, else print "No"
1<=T<=100
Sample Input and Output
| SNo. | Input | Output |
|---|---|---|
| 1 | 2 bba scca | Yes No |
In case 1, viz. String "bba" -
The count of character 'b' is 2. Ascii value of 'b' is also 2.
The count of character 'a' is 1. Ascii value of 'a' is also 1.
Hence string "bba" is super ascii.
Program:
#include <stdio.h>
int main() {
char s[30];
int i,num[30]={0},isascii,n;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
i=0;
isascii=1;
while(s[i]!='\0')
{
if((s[i]>='a')&&(s[i]<='z'))
num[s[i]-'a']++;
s[i]='\0';
i++;
}
for(i=0;i<26;i++)
{
if((num[i]>0)&&(num[i]!=(i+1)))
isascii=0;
num[i]=0;
}
if(isascii)
printf("yes\n");
else
printf("no");
}
return 0;
}
Output:
Related Link: Date Time 2018
Codu And Sum Love 2018
Codu And Sum Love
Problem Description
Constraints
Input Format
Output
Explanation
Program
#include <stdio.h>
long power(long k)
{
long i,j=1;
for(i=1;i<=k;i++)
j=j*2;
return j;
}
long length(long k)
{
long ct=0,n1;
while(k)
{
ct++;
k=k/10;
}
return ct;
}
long reduce(long p1,long r1)
{
long ct=0,k,cnt,rev=0,a[1000],h=0,i,sum1=0;
while(p1)
{
k=p1%10;
a[h]=k;
h++;
p1=p1/10;
}
for(i=1;i>=0;i--)
sum1=sum1*10+a[i];
return sum1;
}
int main() {
long x,n,sum=0,r[70],p,c,f=0,i;
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&x);
p=power(x);
c=length(p);
if(c>2)
{
r[f++]=reduce(p,c);
}
else
r[f++]=p;
}
for(i=0;i<n;i++)
sum=sum+r[i];
printf("%ld",(sum%100));
return 0;
}
Output:
You can also try running it on online IDE: https://ide.geeksforgeeks.org/G3gXokhTbW
Your doubts and feedback are welcomed! you can comment it below Cheers!
Related Link: Super Ascii
Bride Hunting -Code Vita 2018 | round 1 | TCS Code Vita Solution 2018 | Bride Hunting TCS Code Vita solution
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Function to check if given indices are valid in the matrix
int isValid(int row, int col, int N, int M) {
return (row >= 0 && row < N && col >= 0 && col < M);
}
// Function to count the number of qualities a girl possesses
int countQualities(int matrix[][100], int row, int col, int N, int M) {
int count = 0;
for (int i = row - 1; i <= row + 1; i++) {
for (int j = col - 1; j <= col + 1; j++) {
if (isValid(i, j, N, M) && !(i == row && j == col) && matrix[i][j] == 1) {
count++;
}
}
}
return count;
}
// Function to find the suitable bride for Sam
void findBride(int matrix[][100], int N, int M) {
int minDistance = N + M; // Initialize to maximum possible distance
int maxQualities = 0;
int brideRow = -1, brideCol = -1;
// Loop through the matrix to find the bride with maximum qualities
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (matrix[i][j] == 1) {
int qualities = countQualities(matrix, i, j, N, M);
if (qualities > maxQualities) {
maxQualities = qualities;
brideRow = i;
brideCol = j;
} else if (qualities == maxQualities) {
// If multiple brides have the same number of qualities,
// find the one with minimum distance to Sam's house
int distance = abs(0 - i) + abs(0 - j);
if (distance < minDistance) {
minDistance = distance;
brideRow = i;
brideCol = j;
} else if (distance == minDistance) {
printf("Polygamy not allowed\n");
return;
}
}
}
}
}
// If no suitable bride found
if (brideRow == -1 || brideCol == -1) {
printf("No suitable girl found\n");
} else {
printf("%d:%d:%d\n", brideRow + 1, brideCol + 1, maxQualities);
}
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
int matrix[100][100];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
scanf("%d", &matrix[i][j]);
}
}
findBride(matrix, N, M);
return 0;
}
#include<stdio.h>
int main()
{
int n,m,i,g[50][50],j,p,q,max=0,cnt=0,k=1,c=0,u=1,x[30],y[30],t1,min=0, sc[50],e,f,ct=0,a[50],count=0,t2=0,t=0;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%d",&g[i][j]);
} }
g[1][1]=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{ cnt=0;
if(g[i][j]==1)
{
t++;
for(p=i-1;p<=i+1;p++)
{
for(q=j-1;q<=j+1;q++)
{
if(g[p][q]==1)
{ cnt++;
} } }
cnt=cnt-1;
a[k]=cnt;
k++;
} } }
for(k=1;k<=t;k++)
{ if(a[k]>max) max=a[k];
}
if(max==0)
{ printf("No suitable girl found"); goto x; }
for(k=1;k<=t;k++)
{ if(a[k]==max)
c++; }
for(k=1;k<=t;k++)
{ t2=0;
if(a[k]==max)
{ for(i=1;i<=n;i++)
{ for(j=1;j<=m;j++)
{ if(g[i][j]==1) t2++;
if(t2==k)
{ x[u]=i; y[u]=j; u++;
} } } } }
t1=u-1;
if(c==1)
printf("%d:%d:%d",x[1],y[1],max);
else
{ for(u=1;u<=t1;u++)
{ e=x[u]-1;
f=y[u]-1;
if(e>=f)
{ sc[u]=e;
}
else sc[u]=f;
}
min=sc[1];
for(u=1;u<=t1;u++)
{ if(sc[u]<min) min=sc[u];
}
for(u=1;u<=t1;u++)
{ if(sc[u]==min) count++;
}
if(count>1)
printf("Polygamy not allowed");
if(count==1)
{ for(u=1;u<=t1;u++)
{ if(sc[u]==min)
printf("%d:%d:%d",x[u],y[u],max);
} } }
x: return 0;
}
OUTPUT:
6 6
1 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 1 0
0 0 1 1 1 0
0 0 1 1 1 0
0 0 0 0 0 0
Related Links:
Zombie World
Input Format:
Each test case consists of three parts:
1. The total number of zombies (N) and the maximum time allowed (T)
2. Array of size N, which represents the energy of zombies (E)
3. The initial energy level a player (P) and the minimum energy required to advance (D)
Output Format:
Print "Yes" if a player can advance to the next level else print "No".
1<=K<=10
Sample Input and Output
| SNo. | Input | Output |
|---|---|---|
| 1 | 1 2 3 4 5 5 7 | Yes |
PROGRAM:
#include<stdio.h>
int main()
{
int n,t,e[20],i,pe,me,k;
scanf("%d",&k);
while(k)
{
scanf("%d",&n);
scanf("%d",&t);
for(i=0;i<n;i++)
scanf("%d",&e[i]);
scanf("%d",&pe);
scanf("%d",&me);
if(t<n)
goto x;
else
{
for(i=0;i<n;i++)
{
if(pe>=e[i])
{
pe=pe+(pe-e[i]);
}
}
if(pe<=me)
printf("yes\n");
else
x: printf("no\n");
}
k--;
}
return 0;
}
OUTPUT:
12 3
4 5
5 7
Yes
You can directly run it on a IDE: https://ide.geeksforgeeks.org/3un9lTbXuV
You can comment your feedback and doubts if any cheers!
Related Link:Bride Hunting
Minimum Product Array
Minimum Product ArrayTCS codevita 2016 round 1: The task is to find the minimum sum of Products of two arrays of the same size, given that k modifications are allowed on the first array. In each modification, one array element of the first array can either be increased or decreased by 2.Note- the product sum is Summation (A[i]*B[i]) for all i from 1 to n where n is the size of both arrays.Input Format: First line of the input contains n and k delimited by white space Second line contains the Array A (modifiable array) with its values delimited by spaces Third line contains the Array B (non-modifiable array) with its values delimited by spaces.
Output Format:Output the minimum sum of products of the two arrays.Constraints:1 ≤ N ≤ 10^50 ≤ |A[i]|, |B[i]| ≤ 10^50 ≤ K ≤ 10^9Sample Input Output1. 3 5 -311 2 -3-2 3 -52. 5 3 252 3 4 5 43 4 2 3 2Explanation for sample 1:Here total numbers are 3 and total modifications allowed are 5. So we modified A[2], which is -3 and increased it by 10 (as 5 modifications are allowed). Now final sum will be (1 * -2) + (2 * 3) + (7 * -5) -2 + 6 - 35 -31-31 is our final answer.Explanation for sample 2:Here total numbers are 5 and total modifications allowed are 3. So we modified A[1], which is 3 and decreased it by 6 (as 3 modifications are allowed). Now final sum will be (2 * 3) + (-3 * 4) + (4 * 2) + (5 * 3) + (4 * 2) 6 - 12 + 8 + 15 + 8 2525 is our final answer.
PROGRAM:
#include<stdio.h>
int main()
{
int m[10],i,min,max,k,n,p=1,sum=0,u[10],mins;
scanf("%d",&n);
scanf("%d",&k);
for(i=0;i<n;i++)
scanf("%d",&u[i]);
for(i=0;i<n;i++)
scanf("%d",&m[i]);
min=m[0];
max=m[0];
for(i=0;i<n;i++)
{
if(m[i]<min)
min=m[i];
if(m[i]>max)
max=m[i];
}
if (min<0&&max<0)
mins=min<max?min:max;
else if(min>0&&max>0)
mins=max>min?max:min;
else
{
if((min-max)<-(2*min))
mins=min;
else
mins=max;
}
for(i=0;i<n;i++)
{
if(mins==m[i]&&mins>0)
{
u[i]=u[i]-(2*k);
goto x;
}
if(mins==m[i]&&mins<0)
{
u[i]=u[i]+(2*k);
goto x;
}
}
x:for(i=0;i<n;i++)
{
p=u[i]*m[i];
sum=sum+p;
}
printf("%d",sum);
return 0;
}
OUTPUT:
5 32 3 4 5 43 4 2 3 2
25
You can directly run it on a IDE: https://ide.geeksforgeeks.org/lP9ISaZ9yx You can comment your feedback and doubts if any cheers!
Related links: Zombie World
Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution
Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...
-
Bride Hunting Problem Description Sam is an eligible bachelor. He decides to settle down in life and start a family. He goes bri...
-
Problem Description: Some prime numbers can be expressed as Sum of other consecutive prime numbers. For example 5 = 2 + 3 17 = 2 + 3 ...
-
Reverse Gear Problem Description: A futuristic company is building an autonomous car. The scientists at the company are trai...