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

Array Classwork

The document contains the results of a coding assessment taken by a student named AJIN RIBIA P, including 5 coding questions on arrays, adjacent sticks, most occurring elements, mid-aged passengers, and number of white cells in a Nurikabe puzzle board. The student scored 48 out of 50 total marks by providing correct solutions to all questions except being partially correct on the adjacent sticks question.

Uploaded by

AJIN RIBIA P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views

Array Classwork

The document contains the results of a coding assessment taken by a student named AJIN RIBIA P, including 5 coding questions on arrays, adjacent sticks, most occurring elements, mid-aged passengers, and number of white cells in a Nurikabe puzzle board. The student scored 48 out of 50 total marks by providing correct solutions to all questions except being partially correct on the adjacent sticks question.

Uploaded by

AJIN RIBIA P
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Sri Krishna College of Engineering and Technology

Name :AJIN RIBIA P Email :[email protected]


Roll no:22ECE011 Phone :9488470127
Branch :SKCET Department :ECE
Batch :2022_26 Degree :BE-ECE

2022_26_I_PSP using CPP_IRC

Day5_CPP_Arrays_Class

Attempt : 1
Total Mark : 50
Marks Obtained : 48

Section 1 : Coding

1. Create a dynamic integer array and print the sum over the array of each
element * (array element index + 1)

Answer
// You are using GCC
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int size1,i;
int sum=0;
cin>>size1;
int arr[size1];
for(i=0;i<size1;i++)
{
cin>>arr[i];
}
for(int j=0;j<size1;j++)
{
sum=sum+(arr[j]*(j+1));
}
cout<<sum<<endl;
}

Status : Correct Marks : 10/10

2. Adjacent Stick Game

Mukesh and his friends have set out on a vacation to Coorg. They have
booked accommodation in a resort and the resort authorities organize
Campfires every night as a part of their daily activities. Mukesh
volunteered himself for an activity called the "Adjacent Stick Game" where
sticks of different lengths will be placed in a line and Mukesh needs to
remove a stick from each adjacent pair of sticks. He then has to form a
bigger stick by combining all the remaining sticks.

Mukesh needs to know the smallest length of the bigger stick so formed
and needs your help to compute the same. Given the number of sticks N
and the lengths of each of the sticks, write a program to find the smallest
length of the bigger stick that is formed.

Answer
// You are using GCC
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int i,sum,n;
cin>>n;
sum=0;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(int j=0;j<n;j=j+2)
{
if(a[j]<a[j+1])
{
sum=sum+a[j];
}
else
{
sum=sum+a[j+1];
}
}
cout<<sum;

Status : Partially correct Marks : 8/10

3. Most occurring element

An array is filled with one of the values 1, 2, or 3.


Find the value that occurs the most in the array.
If two or more values occur the most number of times print the lower value.

Answer
// You are using GCC
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,s1=0,s2=0,s3=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
switch(a[i])
{
case 1:
s1++;
break;
case 2:
s2++;
break;
case 3:
s3++;
break;
}
}
if(s1>s2 && s1>s3)
{
cout<<"1";
}
else if(s2>s1 && s2>s3)
{
cout<<"2";
}
else if(s3>s2 && s3>s1)
{
cout<<"3";
}
else
{
cout<<"1";
}
}

Status : Correct Marks : 10/10

4. Mid Aged
The Pan Am 73 flight from Bombay to New York en route to Karachi and
Frankfurt was hijacked by a few Palestinian terrorists at the Karachi
International Airport. The senior flight purser Neerja Banhot withered her
fear and helped evacuate the passengers on board.
Neerja very well knew that she would not be able to evacuate all
passengers dodging the hijackers. So she wanted to hand over the
responsibility of evacuating the senior citizens(above 60 years of age) and
children(below 18 years of age) in the flight to the mid-aged passengers
seated in the diagonals

Given n the number of rows of seats and the number of seats in a row and
the ages of passengers in each seat can you find the number of mid-aged
passengers seated in the diagonals.

Answer
// You are using GCC
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i,j,n,s=0;
cin>>n;
int a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
if(a[i][j]>=18 && a[i][j]<=60)
{
s++;
}
}
}
}cout<<s;
}

Status : Correct Marks : 10/10

5. Number of White
Cells
Nurikabe logical game (sometimes called Islands in the Stream) is a binary
determination puzzle. The puzzle is played on a typically rectangular grid
of cells, some of which contain numbers. You must decide for each cell if it
is white or black (by clicking on them) according to the following rules:
• All of the black cells must be connected.
• Each numbered cell must be part of a white island of connected white
cells.
• Each island must have the same number of white cells as the number it
contains (including the numbered cell).
• Two islands may not be connected.
• There cannot be any 2x2 blocks of black cells.
Unnumbered cells start out grey and cycle through white and black when
clicked. Initially numbered cells are white in color.
Problem Statement:
Write a program to find the number of white cells in the final configuration
of the board, given a valid initial configuration. Below figure is the sample
valid initial configuration.

Answer
// You are using GCC
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,s=0;
cin>>n;
int a[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i][j]!=20)
{
s=s+a[i][j];
}
}
}cout<<s;
}

Status : Correct Marks : 10/10

You might also like