GE23131-Programming Using C-2023
GE23131-Programming Using C-2023
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Objective
We're starting out by printing the most famous computing phrase of all time! In the editor below, use
either printf or cout to print the string Hello, World! to stdout.
Input Format
Output Format
Sample Output
Hello, World!
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 printf("Hello, World!");
4 return 0;
5 }
1
Feedback
Expected Got
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Objective
This challenge will help you to learn how to take a character, a string and a sentence as input in C.
To take a single character ch as input, you can use scanf("%c", &ch); and printf("%c", ch) writes a character specified
by the argument char to stdout:
char ch;
scanf("%c", &ch);
printf("%c", ch);
Task
Input Format
Output Format
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 char ch;
4 scanf("%c",&ch);
5 printf("%c",ch); 2
6 return 0;
7 }
Feedback
C C C
Question 3
Correct
Marked out of 7.00
Flag question
Question text
Objective
The fundamental data types in c are int, float and char. Today, we're discussing int and float data types.
The printf() function prints the given statement to the console. The syntax is printf("format string",argument_list);. In
the function, if we are using an integer, character, string or float as argument, then in the format string we have to
write %d (integer), %c (character), %s (string), %f (float) respectively.
The scanf() function reads the input data from the console. The syntax is scanf("format string",argument_list);. For ex:
The scanf("%d",&number) statement reads integer number from the console and stores the given value in
variable number.
To input two integers separated by a space on a single line, the command is scanf("%d %d", &n, &m),
where n and m are the two integers.
Task
Your task is to take two numbers of int data type, two numbers of float data type as input and output their sum:
2. Read 2 lines of input from stdin (according to the sequence given in the 'Input Format' section below) and
initialize your 4 variables.
o Print the sum and difference of two int variable on a new line.
3
o Print the sum and difference of two float variable rounded to one decimal place on a new line.
Input Format
Constraints
Output Format
Print the sum and difference of both integers separated by a space on the first line, and the sum and difference of both
float (scaled to 1 decimal place) separated by a space on the second line.
Sample Input
10 4
4.0 2.0
Sample Output
14 6
6.0 2.0
Explanation
When we sum the integers 10 and 4, we get the integer 14. When we subtract the second number 4 from the first
number 10, we get 6 as their difference.
When we sum the floating-point numbers 4.0 and 2.0, we get 6.0. When we subtract the second number 2.0 from the
first number 4.0, we get 2.0 as their difference.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int a,b;
4 float c,d;
5 scanf("%d%d",&a,&b);
6 scanf("%f%f",&c,&d);
7 printf("%d %d \n",a+b,a-b);
8 printf("%.1f %.1f",c+d,c-d); 4
9 return 0;
10
11 }
Feedback
10 4 14 6 14 6
4.0 2.0 6.0 2.0 6.0 2.0
20 8 28 12 28 12
8.0 4.0 12.0 4.0 12.0 4.0
Finish review
Skip Quiz navigation
Quiz navigation
5
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Write a program to input a name (as a single character) and marks of three tests as m1, m2, and m3 of a student
considering all the three marks have been given in integer format.
Now, you need to calculate the average of the given marks and print it along with the name as mentioned in the output
format section.
All the test marks are in integers and hence calculate the average in integer as well. That is, you need to print the
integer part of the average only and neglect the decimal part.
Input format :
Output format :
Constraints
Marks for each student lie in the range 0 to 100 (both inclusive)
Sample Input 1 :
346
Sample Output 1 :
6
A
Sample Input 2 :
738
Sample Output 2 :
Answer:(penalty regime: 0 %)
1 #include <stdio.h>
2 int main() {
3 char name;
4 int m1,m2,m3;
5 int average;
6 scanf("%c",&name);
7 scanf("%d %d %d",&m1,&m2,&m3);
8 average=(m1+m2+m3)/3;
9 printf("%c\n",name);
10 printf("%d\n",average);
11 return 0;
12 }
Feedback
A A A
3 4 6 4 4
T T T
7 3 8 6 6
R R R
0 100 99 66 66
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Some C data types, their format specifiers, and their most common bit widths are as follows:
7
· Int ("%d"): 32 Bit integer
Reading
To read a data type, use the following syntax:
scanf("`format_specifier`", &val)
char ch;
double d;
For the moment, we can ignore the spacing between format specifiers.
Printing
To print a data type, use the following syntax:
printf("`format_specifier`", val)
char ch = 'd';
double d = 234.432;
Note: You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input
and printing a million lines, it is faster to use scanf and printf.
Input Format
Input consists of the following space-separated values: int, long, char, float, and double, respectively.
Output Format
Print each element on a new line in the same order it was received as input. Note that the floating point value should be
correct up to 3 decimal places and the double to 9 decimal places.
Sample Input
Sample Output
12345678912345
334.230
14049.304930000
Explanation
Print int 3,
followed by char a,
Feedback
3 3
12345678912345 12345678912345
3 12345678912345 a 334.23 14049.30493 a a
334.230 334.230
14049.304930000 14049.304930000
Question 3
Correct
Marked out of 7.00
Flag question
Question text
Write a program to print the ASCII value and the two adjacent characters of the given character.
Input
Output
69
DF
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 char ch;
4 scanf("%c",&ch);
5 int a=(int)ch;
6 printf("%d\n",a);
7 char b=ch-1;
8 char c=ch+1;
9 printf("%c %c \n",b,c); 9
10 return 0;
11
12 }
Feedback
69 69
E
D F D F
Finish review
Skip Quiz navigation
Quiz navigation
10
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Many people think about their height in feet and inches, even in some countries that primarily use the metric system.
Write a program that reads a number of feet from the user, followed by a number of inches. Once these values are read,
your program should compute and display the equivalent number of centimeters.
Hint:
Input Format
Output Format
Note: All of the values should be displayed using two decimal places.
Sample Input 1
56
Sample Output 1
167.64
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a;
5 int b;
6 scanf("%d",&a);
7 scanf("%d",&b);
8 printf("%.2f",(a*12*2.54)+(b*2.54));
9 return 0;
10 }
Feedback 11
Input Expected Got
5
167.64 167.64
6
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Create a program that reads two integers, a and b, from the user. Your program should compute and display: • The sum
of a and b • The difference when b is subtracted from a • The product of a and b • The quotient when a is divided by b •
The remainder when a is divided by b
Input Format
Output Format
Sample
Input 1 100 6
Sample Output
106 94 600 16 4
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a,b;
5 scanf("%d %d",&a,&b);
6 printf("%d\n",a+b);
7 printf("%d\n",a-b);
8 printf("%d\n",a*b);
9 printf("%d\n",a/b);
10 printf("%d\n",a%b);
11 return 0;
12 }
Feedback
106 106
100 94 94
600 600 12
6 16 16
4 4
Question 3
Correct
Marked out of 7.00
Flag question
Question text
A bakery sells loaves of bread for $3.49 each. Day old bread is discounted by 60 percent. Write a program that begins
by reading the number of loaves of day old bread being purchased from the user. Then your program should display the
regular price for the bread, the discount because it is a day old, and the total price. Each of these amounts should be
displayed on its own line with an appropriate label. All of the values should be displayed using two decimal places.
Input Format
Output Format
Note: All of the values should be displayed using two decimal places.
Sample Input 1
10
Sample Output 1
Discount: 20.94
Total: 13.96
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a;
5 scanf("%d",&a);
6 printf("Regular price: %.2f\nDiscount: %.2f\nTotal: %.2f\n",a*3.49,a*3.49*0.6,a*3.49*0.4);
7 return 0;
8 }
Feedback
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Goki recently had a breakup, so he wants to have some more friends in his life. Goki has N people who he can be friends
with, so he decides to choose among them according to their skills set Yi(1<=i<=n). He wants atleast X skills in his
friends. Help Goki find his friends. ________________________________________
INPUT
First line contains a single integer X - denoting the minimum skill required to be Goki's friend. Next line contains one
integer Y - denoting the skill of the person
. ________________________________________
OUTPUT
Print if he can be friend with Goki. 'YES' (without quotes) if he can be friends with Goki else 'NO' (without quotes).
________________________________________
CONSTRAINTS
1<=N<=1000000
1<=X,Y<=1000000
SAMPLE INPUT 1
100 110
SAMPLE OUTPUT 1
YES
SAMPLE INPUT 2
100 90
SAMPLE OUTPUT 2
NO
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int x,y;
5 scanf("%d %d",&x,&y);
6
7 if(y>=x)
8 {
9 printf("YES");
10 }
11 else
12 {
13 printf("NO");
14
15 }
16
14
17
18 }
Feedback
100
YES YES
110
100
NO NO
90
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Before the outbreak of corona virus to the world, a meeting happened in a room in Wuhan. A person who attended that
meeting had COVID-19 and no one in the room knew about it! So everyone started shaking hands with everyone else in
the room as a gesture of respect and after meeting unfortunately everyone got infected! Given the fact that any two
persons shake hand exactly once, Can you tell the total count of handshakes happened in that meeting? Say no to
shakehands. Regularly wash your hands. Stay Safe.
Input Format
Output Format
Constraints
SAMPLE INPUT 1
SAMPLE OUTPUT
SAMPLE INPUT 2
SAMPLE OUTPUT 2
Explanation Case 1: The lonely board member shakes no hands, hence 0. Case 2: There are 2 board members, 1
handshake takes place.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a,b;
5 scanf("%d",&a);
6 b=a*(a-1)/2;
7 printf("%d",b);
8 }
15
Feedback
1 0 0
2 1 1
Question 3
Correct
Marked out of 7.00
Flag question
Question text
In our school days, all of us have enjoyed the Games period. Raghav loves to play cricket and is Captain of his team. He
always wanted to win all cricket matches. But only one last Games period is left in school now. After that he will pass
out from school. So, this match is very important to him. He does not want to lose it. So he has done a lot of planning to
make sure his teams wins. He is worried about only one opponent - Jatin, who is very good batsman. Raghav has figured
out 3 types of bowling techniques, that could be most beneficial for dismissing Jatin. He has given points to each of the
3 techniques. You need to tell him which is the maximum point value, so that Raghav can select best technique. 3
numbers are given in input. Output the maximum of these numbers.
Input:
Output:
SAMPLE INPUT
861
SAMPLE OUTPUT
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a,b,c;
5
6 scanf("%d %d %d",&a,&b,&c);
7 int x=a;
8 if(b>x)
9 {
10 x=b;
11 }
12 if(c>x)
13 {
14 x=c;
15 }
16 printf("%d\n",x);
17 return 0;
18 } 16
Feedback
81 26 15 81 81
Finish review
Skip Quiz navigation
Quiz navigation
17
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Write a program to read two integer values and print true if both the numbers end with the same digit, otherwise print
false. Example: If 698 and 768 are given, program should print true as they both end with 8. Sample Input 1 25 53
Sample Output 1 false Sample Input 2 27 77 Sample Output 2 true
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int x,y;
4 scanf("%d %d",&x,&y);
5 if(x%10==y%10) {
6 printf("true"); }
7 else {
8 printf("false");
9 }
10 }
11
Feedback
25 53 false false
27 77 true true
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Objective
18
Task
Complete the stub code provided in your editor to print whether or not n is weird.
Input Format
Constraints
Output Format
Sample Input 0
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
Explanation
19
Sample Case 0: n = 3
Sample Case 1: n = 24
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int n;
4 scanf("%d",&n);
5 if(n%2==0) {
6 if(n>=2 && n<=5) {
7 printf("Not Weird"); }
8 if(n>=6 && n<=20) {
9 printf("Weird"); }
10 if(n>20) {
11 printf("Not Weird"); } }
12 else {
13 printf("Weird"); }
14 }
15
Feedback
3 Weird Weird
Question 3
Correct
Marked out of 7.00
Flag question
Question text
Three numbers form a Pythagorean triple if the sum of squares of two numbers is equal to the square of the third. For
example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5 You are given three integers, a, b, and c.
They need not be given in increasing order. If they form a Pythagorean triple, then print "yes", otherwise, print "no".
Please note that the output message is in small letters. Sample Input 1 3 5 4 Sample Output 1 yes Sample Input 2 5 8 2
Sample Output 2 no
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int a,b,c;
4 scanf("%d%d%d",&a,&b,&c);
5 if(a*a+b*b==c*c) {
6 printf("yes"); }
7 else if(a*a+c*c==b*b) {
8 printf("yes"); }
9 else if(b*b+c*c==a*a) {
10 printf("yes"); }
11 else {
12 printf("no"); }
13 return 0;
14 } 20
Feedback
3
5 yes yes
4
5
8 no no
2
Finish review
Skip Quiz navigation
Quiz navigation
21
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Write a program that determines the name of a shape from its number of sides. Read the number of sides from the user
and then report the appropriate name as part of a meaningful message. Your program should support shapes with
anywhere from 3 up to (and including) 10 sides. If a number of sides outside of this range is entered then your program
should display an appropriate error message.
Sample Input 1
Sample Output 1
Triangle
Sample Input 2
Sample Output 2
Heptagon
Sample Input 3
11
Sample Output 3
22
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n;
5 scanf("%d",&n);
6 if(n==3)
7 {
8 printf("Triangle");
9 }
10 else if(n==4)
11 {
12 printf("Square");
13 }
14 else if(n==5)
15 {
16 printf("Pentagon");
17 }
18 else if(n==6)
19 {
20 printf("Hexagon");
21 }
22 else if(n==7)
23 {
24 printf("Heptagon");
25 }
26 else if(n==8)
27 {
28 printf("Octagon");
29 }
30 else if(n==9)
31 {
32 printf("Nonagon");
33 }
34 else if(n==10)
35 {
36 printf("Decagon");
37 }
38 else
39 {
40 printf("The number of sides is not supported.");
41 }
42 }
Feedback
3 Triangle Triangle
7 Heptagon Heptagon
11 The number of sides is not supported. The number of sides is not supported.
Question 2
Correct
Marked out of 5.00
Flag question
Question text
The Chinese zodiac assigns animals to years in a 12-year cycle. One 12-year cycle is shown in the table below. The
pattern repeats from there, with 2012 being another year of the Dragon, and 1999 being another year of the Hare.
Year Animal
23
2000 Dragon
2001 Snake
2002 Horse
2003 Sheep
2004 Monkey
2005 Rooster
2006 Dog
2007 Pig
2008 Rat
2009 Ox
2010 Tiger
2011 Hare
Write a program that reads a year from the user and displays the animal associated with that year. Your program
should work correctly for any year greater than or equal to zero, not just the ones listed in the table.
Sample Input 1
2004
Sample Output 1
Monkey
Sample Input 2
2010
Sample Output 2
Tiger
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int year;
5 scanf("%d",&year);
6 if(year%12==8)
7 {
8 printf("Dragon");
9 }
10 else if(year%12==9)
11 {
12 printf("Snake");
13 }
14 else if(year%12==10)
15 {
16 printf("Horse");
24
17
18 }
else if(year%12==11)
19 {
20 printf("Sheep");
21 }
22 else if(year%12==0)
23 {
24 printf("Monkey");
25 }
26 else if(year%12==1)
27 {
28 printf("Rooster");
29 }
30 else if(year%12==2)
31 {
32 printf("Dog");
33 }
34 else if(year%12==3)
35 {
36 printf("Pig");
37 }
38 else if(year%12==4)
39 {
40 printf("Rat");
41 }
42 else if(year%12==5)
43 {
44 printf("Ox");
45 }
46 else if(year%12==6)
47 {
48 printf("Tiger");
49 }
50 else
51 {
52 printf("Hare");
Feedback
Question 3
Correct
Marked out of 7.00
Flag question
Question text
Positions on a chess board are identified by a letter and a number. The letter identifies the column, while the number
identifies the row, as shown below:
25
Write a program that reads a position from the user. Use an if statement to determine if the column begins with a black square or a
white square. Then use modular arithmetic to report the color of the square in that row. For example, if the user enters a1 then your
program should report that the square is black. If the user enters d5 then your program should report that the square is white. Your
program may assume that a valid position will always be entered. It does not need to perform any error checking.
Sample Input 1
a1
Sample Output 1
Sample Input 2
d5
Sample Output 2
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int num,sum;
5 char alpha;
6 scanf("%c%d",&alpha,&num);
7 sum=alpha+num;
8 if(sum%2==0)
9 {
10 printf("The square is black.");
11 }
12 else
13 {
14 printf("The square is white.");
15 }
16 }
Feedback
Finish review
Skip Quiz navigation
26
Quiz navigation
27
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Some data sets specify dates using the year and day of year rather than the year, month, and day of month. The day of
year (DOY) is the sequential day number starting with day 1 on January 1st.
There are two calendars - one for normal years with 365 days, and one for leap years with 366 days. Leap years are
divisible by 4. Centuries, like 1900, are not leap years unless they are divisible by 400. So, 2000 was a leap year.
To find the day of year number for a standard date, scan down the Jan column to find the day of month, then scan
across to the appropriate month column and read the day of year number. Reverse the process to find the standard date
for a given day of year.
Write a program to print the Day of Year of a given date, month and year.
Sample Input 1
18
2020
Sample Output 1
170
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int d,m,y,feb;
5 scanf("%d%d%d",&d,&m,&y);
6 if((y%100==0&&y%400)||(y%4==0))
7 feb=29;
8 else
9 feb=28;
10 switch(m)
11 {
12 case 1:
13 printf("%d",d); 28
14
15 break;
case 2:
16 printf("%d",31+d);
17 break;
18 case 3:
19 printf("%d",31+feb+d);
20 break;
21 case 4:
22 printf("%d",31+feb+31+d);
23 break;
24 case 5:
25 printf("%d",31+feb+31+30+d);
26 break;
27 case 6:
28 printf("%d",31+feb+31+30+31+d);
29 break;
30 case 7:
31 printf("%d",31+feb+31+30+31+30+d);
32 break;
33 case 8:
34 printf("%d",31+feb+31+30+31+30+31+d);
35 break;
36 case 9:
37 printf("%d",31+feb+31+30+31+30+31+31+d);
38 break;
39 case 10:
40 printf("%d",31+feb+31+30+31+30+31+31+30+d);
41 break;
42 case 11:
43 printf("%d",31+feb+31+30+31+30+31+31+30+31+d);
44 break;
45 case 12:
46 printf("%d",31+feb+31+30+31+30+31+31+30+31+30+d);
47 break;
48 }
49 }
Feedback
18
6 170 170
2020
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Suppandi is trying to take part in the local village math quiz. In the first round, he is asked about shapes and areas.
Suppandi, is confused, he was never any good at math. And also, he is bad at remembering the names of shapes.
Instead, you will be helping him calculate the area of shapes.
· And when he is confused, he just says something random. At this point, all you can do is say 0.
29
Input Format
· Length of 1 side
Note: In case of triangle, you can consider the sides as height and length of base
Output Format
Sample Input 1
10
20
Sample Output 1
200
Sample Input 2
30
40
Sample Output 2
600
Sample Input 3
10
10
Sample Output 3 30
100
Sample Input 4
Sample Output 4
Sample Input
10
Sample Output 4
Explanation:
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a,b;
5 char c;
6 scanf("%c%d%d",&c,&a,&b);
7 switch(c)
8 {
9 case 'R':
10 printf("%d",a*b);
11 break;
12 case 'S':
13 printf("%.0f",(0.5)*a*b);
14 break;
15 case 'T':
16 printf("%d",a*b);
17 break;
18 default:
19 printf("0");
31
20
21 }
22 }
Feedback
T
10 200 200
20
S
30 600 600
40
B
2 0 0
11
R
10 300 300
30
S
40 1000 1000
50
Question 3
Correct
Marked out of 7.00
Flag question
Question text
Superman is planning a journey to his home planet. It is very important for him to know which day he arrives there.
They don't follow the 7-day week like us. Instead, they follow a 10-day week with the following days: Day Number Name
of Day 1 Sunday 2 Monday 3 Tuesday 4 Wednesday 5 Thursday 6 Friday 7 Saturday 8 Kryptonday 9 Coluday 10
Daxamday Here are the rules of the calendar: • The calendar starts with Sunday always. • It has only 296 days. After
the 296th day, it goes back to Sunday. You begin your journey on a Sunday and will reach after n. You have to tell on
which day you will arrive when you reach there. Input format: • Contain a number n (0 < n) Output format: Print the
name of the day you are arriving on Example Input 7 Example Output Kryptonday Example Input 1 Example Output
Monday
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n,day;
5 scanf("%d",&n);
6 if(n<296)
7 day=n;
8 else
9 day=n-296;
10 day%=10;
11 day=day+1;
12 day%=10;
13 switch(day)
14 {
15 case 1:
16 printf("Sunday");
17 break;
18 case 2:
19 printf("Monday");
20 break;
21 case 3:
22 printf("Tuesday");
23 break;
24 case 4:
25 printf("Wednesday");
26 break; 32
27 case 5:
28 printf("Thursday");
29 break;
30 case 6:
31 printf("Friday");
32 break;
33 case 7:
34 printf("Saturday");
35 break;
36 case 8:
37 printf("Kryptonday");
38 break;
39 case 9:
40 printf("Coluday");
41 break;
42 case 10:
43 printf("Daxamday");
44 break;
45
46 }
47 }
Feedback
7 Kryptonday Kryptonday
1 Monday Monday
Finish review
Skip Quiz navigation
Quiz navigation
33
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Alice and Bob are playing a game called "Stone Game". Stone game is a two-player game. Let N be the total number of
stones. In each turn, a player can remove either one stone or four stones. The player who picks the last stone, wins.
They follow the "Ladies First" norm. Hence Alice is always the one to make the first move. Your task is to find out
whether Alice can win, if both play the game optimally.
Input Format
First line starts with T, which is the number of test cases. Each test case will contain N number of stones.
Output Format
Constraints
1<=T<=1000
1<=N<=10000
Input
Output
34
Yes
Yes
No
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int T,i=0,n,t;
5 scanf("%d",&T);
6 while(i<T)
7 {
8 scanf("%d",&n);
9 t=n/4;
10 if(t%2==0 && n%2==0)
11 {
12 printf("No\n");
13 }
14 else if(t%2==1 && n%2==1)
15 {
16 printf("No\n");
17 }
18 else
19 {
20 printf("Yes\n");
21 }
22 i++;
23 }
24 }
Feedback
3
Yes Yes
1
Yes Yes
6
No No
7
Question 2
Correct
Marked out of 5.00
Flag question
Question text
You are designing a poster which prints out numbers with a unique style applied to each of them. The styling is based
on the number of closed paths or holes present in a given number.
The number of holes that each of the digits from 0 to 9 have are equal to the number of closed paths in the digit. Their
values are:
1, 2, 3, 5, and 7 = 0 holes.
0, 4, 6, and 9 = 1 hole.
8 = 2 holes.
35
Given a number, you must determine the sum of the number of holes for all of its digits. For example, the number 819
has 3 holes.
Complete the program, it must must return an integer denoting the total number of holes in num.
Constraints
1 ≤ num ≤ 109
There is one line of text containing a single integer num, the value to process.
Sample Input
630
Sample Output
Explanation
Sample Case 1
Sample Input
1288
Sample Output
Explanation
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 { 36
4 int a,b,n=0;
5 scanf("%d",&a);
6 while(a>0)
7 {
8 b=a%10;
9 if(b==0 || b==6 || b==9 || b==4)
10 {
11 n=n+1;
12 }
13 else if(b==8)
14 {
15 n=n+2;
16 }
17 a=a/10;
18
19 }
20 printf("%d",n);
21
22 }
Feedback
630 2 2
1288 4 4
Question 3
Correct
Marked out of 7.00
Flag question
Question text
The problem solvers have found a new Island for coding and named it as Philaland. These smart people were given a
task to make a purchase of items at the Island easier by distributing various coins with different values. Manish has
come up with a solution that if we make coins category starting from $1 till the maximum price of the item present on
Island, then we can purchase any item easily. He added the following example to prove his point.
Let’s suppose the maximum price of an item is 5$ then we can make coins of {$1, $2, $3, $4, $5}to purchase any item
ranging from $1 till $5.
Now Manisha, being a keen observer suggested that we could actually minimize the number of coins required and gave
following distribution {$1, $2, $3}. According to him any item can be purchased one time ranging from $1 to $5.
Everyone was impressed with both of them. Your task is to help Manisha come up with a minimum number of
denominations for any arbitrary max price in Philaland.
Input Format
Contains an integer N denoting the maximum price of the item present on Philaland.
Output Format
Print a single line denoting the minimum number of denominations of coins required.
Constraints 37
1<=T<=100
1<=N<=5000
Sample Input 1:
10
Sample Output 1:
Sample Input 2:
Sample Output 2:
Explanation:
But as per Manisha only {$1, $2, $3, $4} coins are enough to purchase any item ranging from $1 to $10. Hence
minimum is 4. Likewise denominations could also be {$1, $2, $3, $5}. Hence answer is still 4.
But as per Manisha only {$1, $2, $3} coins are enough to purchase any item ranging from $1 to $5. Hence minimum is
3. Likewise, denominations could also be {$1, $2, $4}. Hence answer is still 3.
Answer:(penalty regime: 0 %)
1 #include<stdio.h> 38
2 int main() {
3 int n,r=0;
4 scanf("%d",&n);
5 while(n!=0)
6 {
7 n=n/2;
8 r=r+1;
9
10 }
11 printf("%d",r);
12 }
Feedback
10 4 4
5 3 3
20 5 5
500 9 9
1000 10 10
Finish review
Skip Quiz navigation
Quiz navigation
39
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
A set of N numbers (separated by one space) is passed as input to the program. The program must identify the count of
numbers where the number is odd number.
Input Format:
The first line will contain the N numbers separated by one space.
Boundary Conditions:
3 <= N <= 50
Output Format:
Input:
5 10 15 20 25 30 35 40 45 50
Output:
Explanation:
40
The numbers meeting the criteria are 5, 15, 25, 35, 45.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int n,x=0;
4 while(scanf("%d",&n)==1) {
5 if(n%2!=0) {
6 x++; } }
7 printf("%d",x);
8 return 0;
9 }
Feedback
5 10 15 20 25 30 35 40 45 50 5 5
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Given a number N, return true if and only if it is a confusing number, which satisfies the following condition:
We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9,
8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid. A confusing number is a number
that when rotated 180 degrees becomes a different number with each digit valid.
Example 1:
6 -> 9
Input: 6
Output: true
Explanation:
Example 2:
89 -> 68
Input: 89
41
Output: true
Explanation:
Example 3:
11 -> 11
Input: 11
Output: false
Explanation:
We get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number.
Note:
2. After the rotation we can ignore leading zeros, for example if after rotation we have 0008 then this number is
considered as just 8.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 int n,x,y=1;
4 scanf("%d",&n);
5 while(n!=0 && y==1) {
6 x=n%10; n=n/10;
7 if(x==2 || x==3 || x==4 || x==7) {
8 y++; } }
9 if(y==1) {
10 printf("true"); }
11 else {
12 printf("false"); }
13
14 }
Feedback
6 true true
89 true true
25 false false
Question 3
Correct
Marked out of 7.00
Flag question
42
Question text
A nutritionist is labeling all the best power foods in the market. Every food item arranged in a single line, will have a
value beginning from 1 and increasing by 1 for each, until all items have a value associated with them. An item's value
is the same as the number of macronutrients it has. For example, food item with value 1 has 1 macronutrient, food item
with value 2 has 2 macronutrients, and incrementing in this fashion.
The nutritionist has to recommend the best combination to patients, i.e. maximum total of macronutrients. However,
the nutritionist must avoid prescribing a particular sum of macronutrients (an 'unhealthy' number), and this sum is
known. The nutritionist chooses food items in the increasing order of their value. Compute the highest total of
macronutrients that can be prescribed to a patient, without the sum matching the given 'unhealthy' number.
Here's an illustration:
Given 4 food items (hence value: 1,2,3 and 4), and the unhealthy sum being 6 macronutrients, on choosing items 1, 2, 3
-> the sum is 6, which matches the 'unhealthy' sum. Hence, one of the three needs to be skipped. Thus, the best
combination is from among:
· 2+3+4=9
· 1+3+4=8
· 1+2+4=7
Complete the code in the editor below. It must return an integer that represents the maximum total of macronutrients,
modulo 1000000007 (109 + 7).
Constraints
· 1 ≤ n ≤ 2 × 109
· 1 ≤ k ≤ 4 × 1015
The first line contains an integer, n, that denotes the number of food items.
The second line contains an integer, k, that denotes the unhealthy number.
Sample Input 0
Sample Output 0
43
3
Explanation 0
2. 1 + 2 = 3; observe that this is the max total, and having avoided having exactly k = 2 macronutrients.
Sample Input 1
Sample Output 1
Explanation 1
1. Cannot use item 1 because k = 1 and sum ≡ k has to be avoided at any time.
Sample Case 2
Sample Input 2
Sample Output 2
Explanation 2
44
2 + 3 = 5, is the best case for maximum nutrients.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main() {
3 long long int n,t,i,nut=0;
4 scanf("%lld %lld",&n,&t);
5 for(i=1;i<=n;i++) {
6 nut=nut+i;
7 if(nut==t) {
8 nut=nut-1; } }
9 printf("%lld",nut%1000000007);
10 }
Feedback
2
3 3
2
2
2 2
1
3
5 5
3
Finish review
Skip Quiz navigation
Quiz navigation
45
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Input format:
The lines after that contain a different values for size of the chessboard
Output format:
Print a chessboard of dimensions size * size. Print a Print W for white spaces and B for black spaces.
Input:
Output:
WBW
BWB
WBW
WBWBW
BWBWB
WBWBW
BWBWB
WBWBW
Answer:(penalty regime: 0 %) 46
1 #include<stdio.h>
2 int main()
3 {
4 int T,d,i=0,i1,i2,o;
5 char c;
6 scanf("%d",&T);
7 while(i<T)
8 {
9 scanf("%d",&d);
10 i1=0;
11 while(i1<d)
12 {
13 o=1;
14 i2=0;
15 if(i1%2==0)
16 {
17 o=0;
18 }
19 while(i2<d)
20 {
21 c='B';
22 if(i2%2==o)
23 {
24 c='W';
25 }
26 printf("%c",c);
27 i2++;
28 }
29 i1+=1;
30 printf("\n");
31 }
32 i=i+1;
33 }
34 }
Feedback
WBW WBW
BWB BWB
WBW WBW
2
WBWBW WBWBW
3
BWBWB BWBWB
5
WBWBW WBWBW
BWBWB BWBWB
WBWBW WBWBW
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Each test case contains an integer N and also the starting character of the chessboard
Output Format
47
Print the chessboard as per the given examples
Input:
2W
3B
Output:
WB
BW
BWB
WBW
BWB
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int T,d,i,i1,i2,o,z;
5 char c,s;
6 scanf("%d",&T);
7 for(i=0;i<T;i++)
8 {
9 scanf("%d %c",&d,&s);
10 for(i1=0;i1<d;i1++)
11 {
12 z=(s=='W') ? 0:1;
13 o=(i1%2==z) ? 0:1;
14 for(i2=0;i2<d;i2++)
15 {
16 c=(i2%2==o) ? 'W' : 'B';
17 printf("%c",c);
18 }
19 printf("\n");
20 }
21
22 }
23 return 0;
24 }
Feedback
WB WB
2 BW BW
2 W BWB BWB
3 B WBW WBW
BWB BWB
Question 3
Correct 48
Marked out of 7.00
Flag question
Question text
Decode the logic and print the Pattern that corresponds to given input.
If N= 3
10203010011012
**4050809
****607
1020304017018019020
**50607014015016
****809012013
******10011
Constraints
Input Format
Output
Test Case 1
49
Output
Case #1
10203010011012
**4050809
****607
Case #2
1020304017018019020
**50607014015016
****809012013
******10011
Case #3
102030405026027028029030
**6070809022023024025
****10011012019020021
******13014017018
********15016
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int n,v,p3,c,in,i,i1,i2,t,ti;
4 scanf("%d",&t);
5 for(ti=0;ti<t;ti++){
6 v=0;
7 scanf("%d",&n);
8 printf("Case #%d\n",ti+1);
9 for(i=0;i<n;i++){
10 c=0;
11 if(i>0){
12 for(i1=0;i1<i;i1++) printf("**");
13 }
14 for(i1=i;i1<n;i1++){
15 if(i>0) c++;
16 printf("%d0",++v);
17 }
18 if(i==0){
19 p3=v+(v*(v-1))+1;
20 in=p3;
21 }
22 in=in-c;
23 p3=in;
24 for(i2=i;i2<n;i2++){
25 printf("%d",p3++);
26 if(i2!=n-1) printf("0");
27 }printf("\n");
28 }
29 }
30 }
Feedback
Case #1 Case #1
10203010011012 10203010011012
**4050809 **4050809
****607 ****607
Case #2 Case #2
1020304017018019020 1020304017018019020
50
3 **50607014015016 **50607014015016
3 ****809012013 ****809012013
4 ******10011 ******10011
5 Case #3 Case #3
102030405026027028029030 102030405026027028029030
**6070809022023024025 **6070809022023024025
****10011012019020021 ****10011012019020021
******13014017018 ******13014017018
********15016 ********15016
Finish review
Skip Quiz navigation
Quiz navigation
51
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 3.00
Flag question
Question text
The k-digit number N is an Armstrong number if and only if the k-th power of each digit sums to N.
Example 1:
Input:
153
Output:
true
Explanation:
Example 2:
Input:
123
Output:
false
Explanation: 52
123 is a 3-digit number, and 123 != 1^3 + 2^3 + 3^3 = 36.
Example 3:
Input:
1634
Output:
true
Note:
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 #include<math.h>
3 int main()
4 {
5 int n;
6 scanf("%d",&n);
7 int x=0,n2=n;
8 while(n2!=0)
9 {
10 x++;
11 n2=n2/10;
12
13 }
14 int sum=0;
15 int n3=n,n4;
16 while(n3!=0)
17 {
18 n4=n3%10;
19 sum = sum+pow(n4,x);
20 n3=n3/10;
21
22 }
23 if(n==sum)
24 {
25 printf("true");
26 }
27 else
28 {
29 printf("false");
30
31 }
32 return 0;
33 }
Feedback
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Take a number, reverse it and add it to the original number until the obtained number is a palindrome. Constraints
1<=num<=99999999 Sample Input 1 32 Sample Output 1 55 Sample Input 2 789 Sample Output 2 66066
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int rn, n,nt=0,i=0;
5 scanf("%d",&n);
6 do{
7 nt=n;rn=0;
8 while(n!=0)
9 {
10 rn=rn*10 + n%10;
11 n=n/10;
12
13 }
14 n=nt+rn;
15 i++;
16
17 }
18 while(rn!=nt || i==1);
19 printf("%d",rn);
20 return 0;
21 }
Feedback
32 55 55
Question 3
Correct
Marked out of 7.00
Flag question
Question text
A number is considered lucky if it contains either 3 or 4 or 3 and 4 both in it. Write a program to print the nth lucky
number. Example, 1st lucky number is 3, and 2nd lucky number is 4 and 3rd lucky number is 33 and 4th lucky number
is 34 and so on. Note that 13, 40 etc., are not lucky as they have other numbers in it.
The program should accept a number 'n' as input and display the nth lucky number as output.
Sample Input 1:
Sample Output 1: 54
33
Explanation:
Here the lucky numbers are 3, 4, 33, 34., and the 3rd lucky number is 33.
Sample Input 2:
34
Sample Output 2:
33344
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n=1,i=0,nt,co=0,e;
5 scanf("%d",&e);
6 while(i<e)
7 {
8 nt=n;
9 while(nt!=0)
10 {
11 co=0;
12 if(nt%10!=3 && nt%10!=4)
13 {
14 co=1;
15 break;
16
17 }
18 nt=nt/10;
19 }
20 if(co==0)
21 {
22 i++;
23 }
24 n++;
25 }
26 printf("%d",--n);
27 return 0;
28 }
Feedback
34 33344 33344
Question 1
Correct
Marked out of 3.00
Flag question
Question text
Given an array A of sorted integers and another non negative integer k, find if there exists 2 indices i and j such that
A[i] - A[j] = k, i != j.
Input Format
Output format
Example
Input:
3135
Output:
Input:
3135
56
99
Output:
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int t;
4 scanf("%d",&t);
5 while(t--){
6 int n;
7 scanf("%d",&n);
8 int a[n];
9 for(int i=0;i<n;i++){
10 scanf("%d",&a[i]);
11 }
12 int k;
13 scanf("%d",&k);
14 int flag=0;
15 for(int i=0;i<n;i++){
16 for(int j=i+1;j<n;j++){
17 if(a[i]-a[j]==k || a[j]-a[i]==k){flag=1;break;}
18 }
19 if(flag) break;}
20 printf("%d\n",flag);
21 }
22 }
Feedback
1
3 1 3 51 1
4
1
3 1 3 50 0
99
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Sam loves chocolates and starts buying them on the 1st day of the year. Each day of the year, x, is numbered from 1 to
Y. On days when x is odd, Sam will buy x chocolates; on days when x is even, Sam will not purchase any chocolates.
Complete the code in the editor so that for each day Ni (where 1 ≤ x ≤ N ≤ Y) in array arr, the number of chocolates
Sam purchased (during days 1 through N) is printed on a new line. This is a function-only challenge, so input is handled
for you by the locked stub code in the editor.
Input Format
The first line of input contains an integer, T (the number of test cases). Each line i of the T subsequent lines describes
the ith test case as an integer, Ni (the number of days).
Constraints
1 ≤ T ≤ 2 × 105
1 ≤ N ≤ 2 × 106
1≤x≤N≤Y
Output Format
For each test case, Ti in arr, your calculate method should print the total number of chocolates Sam purchased by day
Ni on a new line.
Sample Input 0
Sample Output 0
Explanation
Test Case 0: N = 1
Sam buys 1 chocolate on day 1, giving us a total of 1 chocolate. Thus, we print 1 on a new line.
Test Case 1: N = 2
Sam buys 1 chocolate on day 1 and 0 on day 2. This gives us a total of 1 chocolate. Thus, we print 1 on a new line.
Test Case 2: N = 3
Sam buys 1 chocolate on day 1, 0 on day 2, and 3 on day 3. This gives us a total of 4 chocolates. Thus, we print 4 on a
new line. 58
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int t;
4 scanf("%d",&t);
5 while(t--){
6 int n,c=0;
7 scanf("%d",&n);
8 for(int i=0;i<=n;i++){
9 if(i%2!=0) c=c+i;
10 }printf("%d\n",c);
11 }
12
13 }
Feedback
3
1 1
1
1 1
2
4 4
3
10
1296 1296
71
2500 2500
100
1849 1849
86
729 729
54
400 400
40
25 25
9
1521 1521
77
25 25
9
49 49
13
2401 2401
98
Question 3
Correct
Marked out of 7.00
Flag question
Question text
The number of goals achieved by two football teams in matches in a league is given in the form of two lists. Consider:
• Football team A, has played three matches, and has scored { 1 , 2 , 3 } goals in each match respectively.
• Football team B, has played two matches, and has scored { 2, 4 } goals in each match respectively.
• Your task is to compute, for each match of team B, the total number of matches of team A, where team A has
scored less than or equal to the number of goals scored by team B in that match.
• For 2 goals scored by team B in its first match, team A has 2 matches with scores 1 and 2.
• For 4 goals scored by team B in its second match, team A has 3 matches with scores 1, 2 and 3.
59
Hence, the answer: {2, 3}.
Complete the code in the editor below. The program must return an array of m positive integers, one for each maxes[i]
representing the total number of elements nums[j] satisfying nums[j] ≤ maxes[i] where 0 ≤ j < n and 0 ≤ i < m, in the
given order.
Constraints
• 2 ≤ n, m ≤ 105
Input from stdin will be processed as follows and passed to the function.
The next n lines each contain an integer describing nums[j] where 0 ≤ j < n.
The next m lines each contain an integer describing maxes[i] where 0 ≤ i < m.
Sample Case 0
Sample Input 0
Sample Output 0
2 60
4
Explanation 0
1. For maxes[0] = 3, we have 2 elements in nums (nums[0] = 1 and nums[2] = 2) that are ≤ maxes[0].
2. For maxes[1] = 5, we have 4 elements in nums (nums[0] = 1, nums[1] = 4, nums[2] = 2, and nums[3] = 4) that are
≤ maxes[1].
Sample Case 1
Sample Input 1
10
Sample Output 1
Explanation 1
We are given, n = 5, nums = [2, 10, 5, 4, 8], m = 4, and maxes = [3, 1, 7, 8].
3. For maxes[2] = 7, we have 3 elements in nums (nums[0] = 2, nums[2] = 5, and nums[3] = 4) that are ≤ maxes[2].
4. For maxes[3] = 8, we have 4 elements in nums (nums[0] = 2, nums[2] = 5, nums[3] = 4, and nums[4] = 8) that are
≤ maxes[3]. 61
Thus, the function returns the array [1, 0, 3, 4] as the answer.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int s1,s2,ans;
5 scanf("%d",&s1);
6 int ta[s1];
7 for(int i=0;i<s1;i++)
8 scanf("%d",&ta[i]);
9 scanf("%d",&s2);
10 int tb[s2];
11 for(int i=0;i<s2;i++)
12 scanf("%d",&tb[i]);
13 for(int j=0;j<s2;j++)
14 {
15 ans=0;
16 for(int i=0;i<s1;i++){
17 if(tb[j]>=ta[i])
18 ans++;
19 }printf("%d\n",ans);
20 }
21 }
Feedback
4
1
4
2 2 2
4 4 4
2
3
5
5
2
10
5
1 1
4
0 0
8
3 3
4
4 4
3
1
7
8
Finish review
Skip Quiz navigation
Quiz navigation
62
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
Given an array of numbers and a window of size k. Print the maximum of numbers inside the window for each step as
the window moves from the beginning of the array.
Input Format
Input contains the array size, no of elements and the window size
Output Format
Constraints
Sample Input 1
13521869
Sample Output 1
555889
For example:
Input Result
8
1 3 5 2 1 8 6 9 5 5 5 8 8 9
3
10
3 7 5 1 2 9 8 5 3 27 7 5 9 9 9 8 5
3
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n,k;
5 scanf("%d",&n);
6 int arr[n];
7 for(int i=0;i<n;i++)
8 {
9 scanf("%d",&arr[i]);
10 }
11 scanf("%d",&k);
12 for(int a=0;a<=n-k;a++)
13 {
14 int max=arr[a]; 63
15 for(int b=a;b<a+k;b++)
16 {
17 if(arr[b]>max)
18 {
19 max=arr[b];
20 }
21 }
22 printf("%d ",max);
23 }
24 }
Feedback
8
1 3 5 2 1 8 6 9 5 5 5 8 8 9 5 5 5 8 8 9
3
10
3 7 5 1 2 9 8 5 3 27 7 5 9 9 9 8 57 7 5 9 9 9 8 5
3
Question 2
Correct
Marked out of 1.00
Flag question
Question text
Input: {5,8,10,13,6,2}
Threshold = 3
Output count = 17
Explanation:
5 {3,2} 2
8 {3,3,2} 3
10 {3,3,3,1} 4
13 {3,3,3,3,1} 5
6 {3,3} 2
2 {2} 1
Input Format
N - no of elements in an array
Array of elements
Threshold value
Output Format
Sample Input 1
5 8 10 13 6 2
64
3
Sample Output 1
17
For example:
Input Result
6
5 8 10 13 6 2 17
3
7
20 35 57 30 56 87 30 33
10
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n,t,count=0;
5 scanf("%d",&n);
6 int arr[n];
7 for(int i=0;i<n;i++)
8 {
9 scanf("%d",&arr[i]);
10 }
11 scanf("%d",&t);
12 for(int j=0;j<n;j++)
13 {
14 while(arr[j]>0)
15 {
16 arr[j]-=t;
17 count++;
18 }
19 }
20 printf("%d",count);
21 }
Feedback
6
5 8 10 13 6 2 17 17
3
7
20 35 57 30 56 87 30 33 33
10
Question 3
Correct
Marked out of 1.00
Flag question
Question text
Input Format
N1 - no of elements in array 1
N2 - no of elements in array 2 65
Array elements for array2
Output Format
Sample Input 1
12369
2 4 5 10
Sample Output 1
1 2 3 4 5 6 9 10
For example:
Input Result
5
1 2 3 6 9
1 2 3 4 5 6 9 10
4
2 4 5 10
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int a,b;
5 scanf("%d",&a);
6 int arr1[a];
7 for(int i=0;i<a;i++)
8 scanf("%d",&arr1[i]);
9 scanf("%d",&b);
10 int arr2[b];
11 for(int i=0;i<b;i++)
12 scanf("%d",&arr2[i]);
13 int p=0,q=0;
14 while((p<a)&&(q<b))
15 {
16 if(arr1[p]<arr2[q])
17 {
18 printf("%d ",arr1[p]);
19 p++;
20 }
21 else if(arr1[p]>arr2[q])
22 {
23 printf("%d ",arr2[q]);
24 q++;
25 }
26 else
27 {
28 printf("%d ",arr1[p]);
29 p++;
30 q++;
31 }
32 }
33 for(int j=p;j<a;j++)
34 {
35 printf("%d ",arr1[j]);
36 }
37 for(int j=q;j<b;j++)
38 {
39 printf("%d ",arr2[j]);
40 }
41 }
Feedback 66
Input Expected Got
5
1 2 3 6 9
1 2 3 4 5 6 9 10 1 2 3 4 5 6 9 10
4
2 4 5 10
Finish review
Skip Quiz navigation
Quiz navigation
67
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
Sunny and Johnny like to pool their money and go to the ice cream parlor. Johnny never buys the same flavor that
Sunny does. The only other rule they have is that they spend all of their money.
Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they have.
For example, they have m = 6 to spend and there are flavors costing cost = [1, 2, 3, 4, 5, 6]. The two flavors costing
1 and 5 meet the criteria. Using 1-based indexing, they are at indices 1 and 4.
Function Description
Complete the code in the editor below. It should return an array containing the indices of the prices of the two flavors
they buy.
· cost: an integer array denoting the cost of each flavor of ice cream
Input Format
The first line contains an integer, t, denoting the number of trips to the ice cream parlor. The next t sets of lines each
describe a visit. Each trip is described as follows:
3. n space-separated integers denoting the cost of each flavor: cost[cost[1], cost[2], . . . , cost[n]].
Note: The index within the cost array represents the flavor of the ice cream purchased.
Constraints
68
· 1 ≤ t ≤ 50
· 2 ≤ m ≤ 104
· 2 ≤ n ≤ 104
Output Format
For each test case, print two space-separated integers denoting the indices of the two flavors purchased, in ascending
order.
Sample Input
14532
2243
Sample Output
14
12
Explanation
Sunny and Johnny make the following two trips to the parlor:
1. The first time, they pool together m = 4 dollars. Of the five flavors available that day, flavors 1 and 4 have a total
cost of 1 + 3 = 4.
2. The second time, they pool together m = 4 dollars. TOf the four flavors available that day, flavors 1 and 2 have a
total cost of 2 + 2 = 4.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int t,m,n,c=0;
4 scanf("%d",&t);
5 for(int i=0;i<t;i++){
6 c=0;
7 scanf("%d\n%d",&m,&n);
8 int arr[n];
9 for(int j=0;j<n;j++){
10 scanf("%d",&arr[j]);
11 } 69
12 for(int a=0;a<n-1;a++){
13 for(int b=a+1;b<n;b++){
14 if(arr[a]+arr[b]==m){
15 printf("%d %d\n",a+1,b+1);
16 c=1;break;
17 }
18 } if(c==1) break;
19 }
20 }
21 return 0;}
Feedback
2
4
5
1 4 1 4
1 4 5 3 2
1 2 1 2
4
4
2 2 4 3
Question 2
Correct
Marked out of 1.00
Flag question
Question text
Numeros the Artist had two lists that were permutations of one another. He was very proud. Unfortunately, while
transporting them from one exhibition to another, some numbers were lost out of the first list. Can you find the missing
numbers?
As an example, the array with some numbers missing, arr = [7, 2, 5, 3, 5, 3]. The original array of numbers brr = [7,
2, 5, 4, 6, 3, 5, 3]. The numbers missing are [4, 6].
Notes
· If a number occurs multiple times in the lists, you must ensure that the frequency of that number in both lists is
the same. If that is not the case, then it is also a missing number.
· The difference between maximum and minimum number in the second list is less than or equal to 100.
Complete the code in the editor below. It should return an array of missing numbers.
Input Format
70
There will be four lines of input:
Constraints
· 1 ≤ n, m ≤ 2 x 105
· n≤m
· 1 ≤ brr[i] ≤ 2 x 104
Output Format
Sample Input
10
203 204 205 206 207 208 203 204 205 206
13
203 204 204 205 206 207 205 208 203 206 205 206 204
Sample Output
Explanation
204 is present in both arrays. Its frequency in arr is 2, while its frequency in brr is 3. Similarly, 205 and 206 occur
twice in arr, but three times in brr. The rest of the numbers have the same frequencies in both lists.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int n,m,c,c1=0,co;
4 scanf("%d",&n);
5 int arr[n];
6 for(int a=0;a<n;a++){
7 scanf("%d",&arr[a]);
8 }
9 scanf("%d",&m); 71
10 int brr[m],ans[m];
11 for(int b=0;b<m;b++){
12 scanf("%d",&brr[b]);
13 }
14 for(int j=0;j<m;j++)
15 {
16 c=0;
17 for(int i=0;i<n;i++){
18 if(arr[i]==brr[j]){
19 c=1;
20 arr[i]=-1;
21 break;
22 }
23 }
24 if(c==0){
25 ans[c1]=brr[j];
26 c1++;
27 }
28 }
29 for(int a=0;a<c1;a++){
30 co=0;
31 for(int b=0;b<c1;b++){
32 if(ans[b]<ans[a])
33 co++;
34 }
35 int temp=ans[a];
36 ans[a]=ans[co];
37 ans[co]=temp;
38 }
39 for(int i=0;i<c1;i++)
40 printf("%d ",ans[i]);
41
42 return 0;
43
44 }
Feedback
10
203 204 205 206 207 208 203 204 205 206
204 205 206 204 205 206
13
203 204 204 205 206 207 205 208 203 206 205 206 204
Question 3
Correct
Marked out of 1.00
Flag question
Question text
Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all
elements to the left is equal to the sum of all elements to the right. For instance, given the array arr = [5, 6, 8, 11], 8
is between two subarrays that sum to 11. If your starting array is [1], that element satisfies the rule as left and right
sum to 0.
You will be given arrays of integers and must determine whether there is an element that meets the criterion.
Complete the code in the editor below. It should return a string, either YES if there is an element meeting the criterion
or NO otherwise.
- The first line contains n, the number of elements in the array arr.
Constraints
· 1 ≤ T ≤ 10
· 1 ≤ n ≤ 105
· 1 ≤ arr[i] ≤ 2 x 104
· 0≤i≤n
Output Format
For each test case print YES if there exists an element in the array, such that the sum of the elements on its left is equal
to the sum of the elements on its right; otherwise print NO.
Sample Input 0
123
1233
Sample Output 0
NO
YES
Explanation 0
For the second test case, arr[0] + arr[1] = arr[3], therefore index 2 satisfies the given conditions.
Sample Input 1
73
3
11411
2000
0020
Sample Output 1
YES
YES
YES
Explanation 1
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main(){
3 int t,n,Is,rs,m;
4 scanf("%d",&t);
5 for(int i=0;i<t;i++){
6 Is=0;
7 rs=0;
8 scanf("%d",&n);
9 int arr[n];
10 for(int j=0;j<n;j++)
11 scanf("%d",&arr[j]);
12 m=n/2;
13 if(arr[m]==0){
14 for(m=0;arr[m]==0 && m<n;m++);
15 }
16 for(int j=0;j<=m;j++)
17 Is=Is+arr[j];
18 for(int j=m;j<n;j++)
19 rs=rs+arr[j];
20 printf("%s\n",(Is==rs)?"YES":"NO");
21
22 }
23 return 0;
24 }
Feedback
3
5
1 1 4 1 1 YES YES
4 YES YES
2 0 0 0 YES YES
4
0 0 2 0 74
2
3
NO NO
1 2 3
YES YES
4
1 2 3 3
Finish review
Skip Quiz navigation
Quiz navigation
75
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
Coders here is a simple task for you, you have given an array of size N and an integer M.
Your task is to calculate the difference between maximum sum and minimum sum of N-M elements of the given
array.
Constraints:
1<=t<=10
1<=n<=1000
1<=a[i]<=1000
Input:
Next line contains N space separated integers denoting the elements of array
Output:
SAMPLE INPUT
51
12345
SAMPLE OUTPUT
76
4
Explanation
M is 1 and N is 5 so you have to calculate maximum and minimum sum using (5-1 =) 4 elements.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int t;
5 scanf("%d",&t);
6 while(t--)
7 {
8 int n,m,d,min,temp;
9 scanf("%d %d",&n,&m);
10 d=n-m;
11 int arr[n];
12 for(int i=0;i<n;i++)
13 scanf("%d",&arr[i]);
14 for(int j=0;j<n;j++)
15 {
16 min=j;
17 for(int k=j;k<n;k++)
18 {
19 if(arr[k]<arr[min])
20 min=k;
21 }
22 temp=arr[min];
23 arr[min]=arr[j];
24 arr[j]=temp;
25 }
26 int maxsum=0,minsum=0;
27 for(int a=0;a<d;a++)
28 minsum+=arr[a];
29 for(int b=n-1;b>m-1;b--)
30 maxsum+=arr[b];
31 printf("%d\n",maxsum-minsum);
32
33 }
34
35 }
Feedback
1
5 1 4 4
1 2 3 4 5
Question 2
Correct
Marked out of 1.00
Flag question
Question text
A new deadly virus has infected large population of a planet. A brilliant scientist has discovered a new strain of virus
77
which can cure this disease. Vaccine produced from this virus has various strength depending on midichlorians count. A
person is cured only if midichlorians count in vaccine batch is more than midichlorians count of person. A doctor
receives a new set of report which contains midichlorians count of each infected patient, Practo stores all vaccine
doctor has and their midichlorians count. You need to determine if doctor can save all patients with the vaccines he has.
The number of vaccines and patients are equal.
Input Format
First line contains the number of vaccines - N. Second line contains N integers, which are strength of vaccines. Third
line contains N integers, which are midichlorians count of patients.
Output Format
Input Constraint
1 < N < 10
SAMPLE INPUT
SAMPLE OUTPUT
No
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n,min1,min2,temp,flag=1;
5 scanf("%d",&n);
6 int vac[n],pat[n];
7 for(int i=0;i<n;i++)
8 scanf("%d",&vac[i]);
9 for(int i=0;i<n;i++)
10 scanf("%d",&pat[i]);
11
12 for(int j=0;j<n-1;j++)
13 {
14 min1=j,min2=j;
15 for(int k=j;k<n;k++)
16 {
17 if(vac[k]<vac[min1])
18 min1=k;
78
19 if(pat[k]<pat[min2])
20 min2=k;
21 }
22
23 temp=vac[min1];
24 vac[min1]=vac[j];
25 vac[j]=temp;
26
27 temp=pat[min2];
28 pat[min2]=pat[j];
29 pat[j]=temp;
30 }
31 for(int i=0;i<n;i++)
32 {
33 if(vac[i]<=pat[i])
34 {
35 flag=0;
36 break;
37 }
38 }
39 if(flag==1)
40 printf("Yes");
41 else
42 printf("No");
43 }
Feedback
5
123 146 454 542 456 No No
100 328 248 689 200
Question 3
Correct
Marked out of 1.00
Flag question
Question text
You are given an array of n integer numbers a1, a2, . . . , an. Calculate the number of pair of indices (i, j) such that 1 ≤
i < j ≤ n and ai xor aj = 0.
Input format
Output format
Constraints
1 ≤ n ≤ 106
79
1 ≤ ai ≤ 109
SAMPLE INPUT
13143
SAMPLE OUTPUT
Explanation
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n,count=0;
5 scanf("%d",&n);
6 int arr[n];
7 for(int i=0;i<n;i++)
8 scanf("%d",&arr[i]);
9 for(int i=0;i<n-1;i++)
10 {
11 for(int j=i+1;j<n;j++)
12 {
13 if((arr[i]^arr[j])==0)
14 count++;
15 }
16 }
17 printf("%d",count);
18 }
Feedback
5
2 2
1 3 1 4 3
Question 4
Correct
Marked out of 1.00
Flag question
Question text 80
You are given an array A of non-negative integers of size m. Your task is to sort the array in non-decreasing order and
print out the original indices of the new sorted array.
Example:
A={4,5,3,7,1}
INPUT :
OUTPUT :
CONSTRAINTS:
1<=m<=106
0<=A[i]<=106
SAMPLE INPUT
45371
SAMPLE OUTPUT
42013
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int n;
5 scanf("%d",&n);
6 int arr[n];
7 for(int i=0;i<n;i++)
8 scanf("%d",&arr[i]); 81
9 int max=arr[0];
10 for(int i=1;i<n;i++)
11 {
12 if(arr[i]>max)
13 max=arr[i];
14 }
15 max++;
16 int min=0;
17 for(int a=0;a<n;a++)
18 {
19 for(int b=0;b<n;b++)
20 {
21 if(arr[b]<arr[min])
22 min=b;
23
24 }
25 printf("%d ",min);
26 arr[min]=max;
27 }
28 }
Feedback
5
4 2 0 1 3 4 2 0 1 3
4 5 3 7 1
Finish review
Skip Quiz navigation
Quiz navigation
Question 1 This page Question 2 This page Question 3 This page Question 4 This page
Show one page at a time Finish review
82
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
You are given a two-dimensional 3*3 array starting from A [0][0]. You should add the alternate elements of the array
and print its sum. It should print two different numbers the first being sum of A 0 0, A 0 2, A 1 1, A 2 0, A 2 2 and A 0 1,
A 1 0, A 1 2, A 2 1.
Input Format
First and only line contains the value of array separated by single space.
vk
Output Format
SAMPLE INPUT
123456789
SAMPLE OUTPUT
25
20
83
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int arr[3][3];
5 for(int i=0;i<3;i++)
6 {
7 for(int j=0;j<3;j++)
8 {
9 scanf("%d",&arr[i][j]);
10 }
11 }
12 int odd=0,even=0;
13 for(int i=0;i<3;i++)
14 {
15 for(int j=0;j<3;j++)
16 {
17 if((i+j)%2!=0)
18 odd+=arr[i][j];
19 else
20 even+=arr[i][j];
21 }
22 }
23 printf("%d\n%d",even,odd);
24
25 }
Feedback
25 25
1 2 3 4 5 6 7 8 9
20 20
2591 2591
21 422 423 443 586 645 657 846 904
2356 2356
Question 2
Correct
Marked out of 5.00
Flag question
Question text
Microsoft has come to hire interns from your college. N students got shortlisted out of which few were males and a few
females. All the students have been assigned talent levels. Smaller the talent level, lesser is your chance to be selected.
Microsoft wants to create the result list where it wants the candidates sorted according to their talent levels, but there
is a catch. This time Microsoft wants to hire female candidates first and then male candidates.
The task is to create a list where first all-female candidates are sorted in a descending order and then male candidates
are sorted in a descending order.
Input Format
The first line contains an integer N denoting the number of students. Next, N lines contain two space-separated
integers, ai and bi.
The first integer, ai will be either 1(for a male candidate) or 0(for female candidate).
0 <= ai <= 1
Output Format
Output space-separated integers, which first contains the talent levels of all female candidates sorted in descending
order and then the talent levels of male candidates in descending order.
SAMPLE INPUT
03
16
02
07
1 15
SAMPLE OUTPUT
7 3 2 15 6
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 struct data
3 {
4 int gen;int tal;
5
6 };
7 int main()
8 {
9 int n;
10 scanf("%d",&n);
11 struct data a[n];
12 for(int i=0;i<n;i++)
13 scanf("%d %d",&a[i].gen,&a[i].tal);
14 for(int i=0;i<n-1;i++)
15 {
16 for(int j=0;j<n-i-1;++j)
17 {
18 if(a[j].tal<a[j+1].tal)
19 {
20 struct data temp=a[j];
21 a[j]=a[j+1];
22 a[j+1]=temp;
23 }
24 }
25 }
26 for(int i=0;i<n;i++)
27 {
28 if(a[i].gen==0)
29 printf("%d ",a[i].tal);
30
85
31 }
for(int i=0;i<n;++i)
32 {
33 if(a[i].gen==1)
34 printf("%d ",a[i].tal);
35 }
36 }
Feedback
5
0 3
1 6
7 3 2 15 6 7 3 2 15 6
0 2
0 7
1 15
6
0 1
0 26
0 39 39 37 26 13 7 1 39 37 26 13 7 1
0 37
0 7
0 13
12
1 12
1 14
1 18
1 1
1 2
1 3 31 29 18 14 12 10 9 8 5 3 2 1 31 29 18 14 12 10 9 8 5 3 2 1
1 5
1 8
1 9
1 10
0 29
0 31
12
0 12
1 12
0 12
1 12
0 12
0 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
1 12
0 12
1 12
1 12
0 12
1 12
Question 3
Correct
Marked out of 1.00
Flag question
Question text
Shyam Lal, a wealthy landlord from the state of Rajasthan, being an old fellow and tired of doing hard work, decided to
sell all his farmland and to live rest of his life with that money. No other farmer is rich enough to buy all his land so he
decided to partition the land into rectangular plots of different sizes with different cost per unit area. So, he sold these
plots to the farmers but made a mistake. Being illiterate, he made partitions that could be overlapping. When the
farmers came to know about it, they ran to him for compensation of extra money they paid to him. So, he decided to
return all the money to the farmers of that land which was overlapping with other farmer's land to settle down the
conflict. All the portion of conflicted land will be taken back by the landlord.
86
To decide the total compensation, he has to calculate the total amount of money to return back to farmers with the
same cost they had purchased from him. Suppose, Shyam Lal has a total land area of 1000 x 1000 equal square blocks
where each block is equivalent to a unit square area which can be represented on the co-ordinate axis. Now find the
total amount of money, he has to return to the farmers. Help Shyam Lal to accomplish this task.
Input Format:
The first line of the input contains an integer N, denoting the total number of land pieces he had distributed. Next N
line contains the 5 space separated integers (X1, Y1), (X2, Y2) to represent a rectangular piece of land, and cost per
unit area C.
(X1, Y1) and (X2, Y2) are the locations of first and last square block on the diagonal of the rectangular region.
Output Format:
Print the total amount he has to return to farmers to solve the conflict.
Constraints:
1 ≤ N ≤ 100
1 ≤ X1 ≤ X2 ≤ 1000
1 ≤ Y1 ≤ Y2 ≤ 1000
1 ≤ C ≤ 1000
SAMPLE INPUT
14461
43662
22543
SAMPLE OUTPUT
35
Explanation
87
vk
For given sample input (see given graph for reference), compensation money for different farmers is as follows:
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int i,j,n,x1,x2,y1,y2,t=0;
5 long long total=0;
6 int arr[1001][1001]={0};
7 scanf("%d",&n);
8 while(n--)
9 {
10 scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&t);
11 for(i=x1;i<=x2;i++)
12 {
13 for(j=y1;j<=y2;j++)
14 {
15 if(arr[i][j]==0)
16 arr[i][j]+=t;
17 else if(arr[i][j]>0)
18 arr[i][j]=(-1)*(arr[i][j]+t);
19 else if(arr[i][j]<0)
20 arr[i][j]-=t;
21
22 }
23 }
24 }
25 for(i=1;i<1001;i++)
26 {
27 for(j=1;j<1001;j++)
28 {
29 if(arr[i][j]<0)
30 total+=arr[i][j];
31 }
32 }
33 printf("%lld\n",(-1)*total);
34 return 0;
35 }
Feedback 88
Input Expected Got
3
1 4 4 6 1
35 35
4 3 6 6 2
2 2 5 4 3
1
0 0
48 12 49 27 8
3
88 34 99 76 44
10500 10500
82 65 94 100 81
58 16 65 66 7
Finish review
Skip Quiz navigation
Quiz navigation
89
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
Given a string, s, consisting of alphabets and digits, find the frequency of each digit in the given string.
Input Format
The first line contains a string, num which is the given number.
Constraints
1 ≤ len(num) ≤ 1000
All the elements of num are made of English alphabets and digits.
Output Format
Print ten space-separated integers in a single line denoting the frequency of each digit from 0 to 9.
Sample Input 0
a11472o5t6
Sample Output 0
0210111100
Explanation 0
90
· 1 occurs two times.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 char str[1000];
5 scanf("%s",str);
6 int hash[10]={0,0,0,0,0,0,0,0,0,0,};
7 int temp;
8 for(int i=0;str[i]!='\0';i++)
9 {
10 temp=str[i]-'0';
11 if(temp<=9&&temp>=0)
12 {
13 hash[temp]++;
14 }
15 }
16 for(int i=0;i<=9;i++)
17 {
18 printf("%d ",hash[i]);
19 }
20 return 0;
21 }
Feedback
a11472o5t6 0 2 1 0 1 1 1 1 0 00 2 1 0 1 1 1 1 0 0
lw4n88j12n1 0 2 1 0 1 0 0 0 2 00 2 1 0 1 0 0 0 2 0
1v88886l256338ar0ekk 1 1 1 2 0 1 2 0 5 0 1 1 1 2 0 1 2 0 5 0
Question 2
Correct
Marked out of 1.00
Flag question
Question text
Today, Monk went for a walk in a garden. There are many trees in the garden and each tree has an English alphabet on
it. While Monk was walking, he noticed that all trees with vowels on it are not in good state. He decided to take care of
them. So, he asked you to tell him the count of such trees in the garden.
Note: The following letters are vowels: 'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o' and 'u'.
Input:
The first line consists of an integer T denoting the number of test cases.
Each test case consists of only one string, each character of string denoting the alphabet (may be lowercase or
uppercase) on a tree in the garden.
Output:
1 ≤ T ≤ 10
1 ≤ length of string ≤ 105
SAMPLE INPUT
nBBZLaosnm
JHkIsnZtTL
SAMPLE OUTPUT
Explanation
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 int t;
5 scanf("%d",&t);
6 while(t--)
7 {
8 char str[100000];
9 int count=0;
10 scanf("%s",str);
11 for(int i=0;str[i]!='\0';i++)
12 {
13 char c= str[i];
14 if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u')||(c=='A')||(c=='E')||(c=='I')||(c=='O')||(c=='U'))
15 count++;
16 }
17 printf("%d\n",count);
18 }
19 return 0;
20 }
Feedback
2
2 2
nBBZLaosnm
1 1
JHkIsnZtTL
2
2 2
nBBZLaosnm
1 1
JHkIsnZtTL
Correct
Marked out of 1.00
Flag question
Question text
Input Format
Constraints
1 ≤ len(s) ≤ 1000
Output Format
Sample Input 0
This is C
Sample Output 0
This
is
Explanation 0
In the given string, there are three words ["This", "is", "C"]. We have to print each of these words in a new line.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 char s[1000];
5 scanf("%[^\n]s",s);
6 for(int i=0;s[i]!='\0';i++)
7 {
8 if (s[i]!=' ')
9 printf("%c",s[i]);
10 else
11 printf("\n");
12 }
13 return 0;
14 }
93
Feedback
This This
This is C is is
C C
Learning Learning
C C
Learning C is fun
is is
fun fun
Question 4
Correct
Marked out of 1.00
Flag question
Question text
Input Format
You are given two strings, a and b, separated by a new line. Each string will consist of lower case Latin characters ('a'-
'z').
Output Format
In the first line print two space-separated integers, representing the length of a and b respectively.
In the second line print the string produced by concatenating a and b (a + b).
In the third line print two strings separated by a space, a' and b'. a' and b' are the same as a and b, respectively,
except that their first characters are swapped.
Sample Input
abcd
ef
Sample Output
42
abcdef
ebcd af
Explanation 94
a = "abcd"
b = "ef"
|a| = 4
|b| = 2
a + b = "abcdef"
a' = "ebcd"
b' = "af"
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 {
4 char str1[10],str2[10],t;
5 int i=0,j=0;
6 int count1=0,count2=0;
7 scanf("%s",str1);
8 scanf("%s",str2);
9 while(str1[i]!='\0')
10 {
11 count1++;
12 i++;
13
14 }
15 while(str2[j]!='\0')
16 {
17 count2++;
18 j++;
19 }
20 printf("%d %d\n",count1,count2);
21 printf("%s%s\n",str1,str2);
22 t=str1[0];
23 str1[0]=str2[0];
24 str2[0]=t;
25 printf("%s %s",str1,str2);
26 return 0;
27 }
Feedback
4 2 4 2
abcd
abcdef abcdef
ef
ebcd af ebcd af
Finish review
Skip Quiz navigation
Quiz navigation
Question 1 This page Question 2 This page Question 3 This page Question 4 This page
Show one page at a time Finish review
95
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
Two strings A and B comprising of lower case English letters are compatible if they are equal or can be made equal by
following this step any number of times:
· Select a prefix from the string A (possibly empty), and increase the alphabetical value of all the characters in the
prefix by the same valid amount. For example, if the string is xyz and we select the prefix xy then we can convert it to
yx by increasing the alphabetical value by 1. But if we select the prefix xyz then we cannot increase the alphabetical
value.
Input format
Output format
For each test case, print YES if string A can be converted to string B, otherwise print NO.
Constraints
1 ≤ len(A) ≤ 1000000
1 ≤ len(B) ≤ 1000000
SAMPLE INPUT
abaca
cdbda
SAMPLE OUTPUT
96
YES
Explanation
The string abaca can be converted to bcbda in one move and to cdbda in the next move.
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 char str1[1000000],str2[1000000];
6 int flag=1;
7 scanf("%s",str1);
8 scanf("%s",str2);
9 int a=strlen(str1);
10 int b=strlen(str2);
11 if(a==b)
12
13 {
14 for(int i=a-1;i>=0;i--)
15 {
16 while(str1[i]!=str2[i])
17 {
18 for(int j=0;j<=i;j++)
19 {
20 if(str1[j]<'z')
21 str1[j]++;
22 else
23 {
24 flag=0;
25 break;
26 }
27 if(flag==0)
28 break;
29 }
30 }
31 }
32 }
33 else
34 flag=0;
35
36 if(flag==0)
37 printf("NO");
38 else
39 printf("YES");
40 return 0;
41 }
Feedback
abaca
YES YES
cdbda
Question 2
Correct
Marked out of 1.00
Flag question
Question text
97
Danny has a possible list of passwords of Manny's facebook account. All passwords length is odd. But Danny knows that
Manny is a big fan of palindromes. So, his password and reverse of his password both should be in the list.
You have to print the length of Manny's password and it's middle character.
INPUT
The first line of input contains the integer N, the number of possible passwords.
Each of the following N lines contains a single word, its length being an odd number greater than 2 and lesser than 14.
All characters are lowercase letters of the English alphabet.
OUTPUT
The first and only line of output must contain the length of the correct password and its central letter.
CONSTRAINTS
1 ≤ N ≤ 100
SAMPLE INPUT
abc
def
feg
cba
SAMPLE OUTPUT
3b
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 int n,flag=0;
6 char temp;
7 scanf("%d",&n);
8 char words[n][14];
9 for(int i=0;i<n;i++)
10 scanf("%s",words[i]);
11 char reverse[14];
12 for(int i=0;i<n-1;i++)
13 { 98
14 strcpy(reverse,words[i]);
15 int size=strlen(reverse);
16
17 for(int k=0;k<size/2;k++)
18 {
19 temp=reverse[k];
20 reverse[k]=reverse[size-k-1];
21 reverse[size-k-1]=temp;
22
23 }
24 for(int j=i+1;j<n;j++)
25 {
26 if(strcmp(reverse,words[j])==0)
27 {
28 flag=1;
29 break;
30 }
31 }
32 if(flag==1)
33 break;
34 }
35 int len=strlen(reverse);
36 printf("%d %c ",len,reverse[len/2]);
37 return 0;
38 }
Feedback
4
abc
def 3 b 3 b
feg
cba
Question 3
Correct
Marked out of 1.00
Flag question
Question text
Joey loves to eat Pizza. But he is worried as the quality of pizza made by most of the restaurants is deteriorating. The
last few pizzas ordered by him did not taste good :(. Joey is feeling extremely hungry and wants to eat pizza. But he is
confused about the restaurant from where he should order. As always he asks Chandler for help.
Chandler suggests that Joey should give each restaurant some points, and then choose the restaurant having maximum
points. If more than one restaurant has same points, Joey can choose the one with lexicographically smallest name.
Joey has assigned points to all the restaurants, but can't figure out which restaurant satisfies Chandler's criteria. Can
you help him out?
Input:
Next N lines contain Name of Restaurant and Points awarded by Joey, separated by a space. Restaurant name has no
spaces, all lowercase letters and will not be more than 20 characters.
Output: 99
Print the name of the restaurant that Joey should choose.
Constraints:
SAMPLE INPUT
Pizzeria 108
Dominos 145
Pizzapizza 49
SAMPLE OUTPUT
Dominos
Explanation
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 int n;
6 scanf("%d",&n);
7 char res[n][21];
8 int rate[n];
9 for(int i=0;i<n;i++)
10 {
11 scanf("%s",res[i]);
12 scanf("%d",&rate[i]);
13
14 }
15 int max=rate[0];
16 char ans[20];
17 strcpy(ans,res[0]);
18 for(int i=1;i<n;i++)
19 {
20 if(rate[i]>max)
21 {
22 max=rate[i];
23 strcpy(ans,res[i]);
24
25 }
26 else if(rate[i]==max)
27 {
28 if(strcmp(res[i],ans)<0)
29 strcpy(ans,res[i]);
30 }
31 }
32 printf("%s",ans); 100
33 return 0;
34 }
Feedback
3
Pizzeria 108
Dominos Dominos
Dominos 145
Pizzapizza 49
Question 4
Correct
Marked out of 1.00
Flag question
Question text
These days Bechan Chacha is depressed because his crush gave him list of mobile number some of them are valid and
some of them are invalid. Bechan Chacha has special power that he can pick his crush number only if he has valid set of
mobile numbers. Help him to determine the valid numbers.
You are given a string "S" and you have to determine whether it is Valid mobile number or not. Mobile number is valid
only if it is of length 10 , consists of numeric values and it shouldn't have prefix zeroes.
Input:
Output:
Constraints:
SAMPLE INPUT
1234567890
0123456789
0123456.87
101
SAMPLE OUTPUT
YES
NO
NO
Answer:(penalty regime: 0 %)
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 int t;
6 scanf("%d",&t);
7 while(t--)
8 {
9 int flag=1;
10 char s[100000];
11 scanf("%s",s);
12 int k=strlen(s);
13
14 if(k==10)
15 {
16 for(int i=0;i<10;i++)
17 {
18 if(s[0]=='0')
19 {
20 flag=0;
21 break;
22 }
23 if(s[i]<'0'||s[i]>'9')
24 {
25 flag=0;
26 break;
27 }
28 }
29 }
30 else
31 flag=0;
32 if(flag==1)
33 printf("YES\n");
34 else
35 printf("NO\n");
36 }
37 return 0;
38
39 }
Feedback
3
YES YES
1234567890
NO NO
0123456789
NO NO
0123456.87
Finish review
Skip Quiz navigation
Quiz navigation
Question 1 This page Question 2 This page Question 3 This page Question 4 This page
Show one page at a time Finish review
102
Skip to main content
REC-First Year-2023
Question 1
Correct
Marked out of 1.00
Flag question
Question text
A binary number is a combination of 1s and 0s. Its nth least significant digit is the nth digit starting from the right
starting with 1. Given a decimal number, convert it to binary and determine the value of the the 4th least significant
digit.
Example
number = 23
· The value of the 4th index from the right in the binary representation is 0.
Function Description
Returns:
int: an integer 0 or 1 matching the 4th least significant digit in the binary representation of number.
Constraints
Input from stdin will be processed as follows and passed to the function.
103
The only line contains an integer, number.
Sample Case 0
Sample Input 0
STDIN Function
----- --------
32 → number = 32
Sample Output 0
Explanation 0
· The value of the 4th index from the right in the binary representation is 0.
Sample Case 1
Sample Input 1
STDIN Function
----- --------
77 → number = 77
Sample Output 1
Explanation 1
· The value of the 4th index from the right in the binary representation is 1.
Answer:(penalty regime: 0 %)
Reset answer
1 /*
2 * Complete the 'fourthBit' function below.
3 *
4 * The function is expected to return an INTEGER.
5 * The function accepts INTEGER number as parameter. 104
6 */
7
8 int fourthBit(int number)
9 {
10 int binary[32];
11 int i=0;
12 while(number>0)
13 {
14 binary[i]=number%2;
15 number/=2;
16 i++;
17 }
18 if(i>=4)
19 {
20 return binary[3];
21
22 }
23 else
24 return 0;
25 }
Feedback
printf("%d", fourthBit(32)) 0 0
printf("%d", fourthBit(77)) 1 1
Question 2
Correct
Marked out of 1.00
Flag question
Question text
Determine the factors of a number (i.e., all positive integer values that evenly divide into a number) and then return the
pth element of the list, sorted ascending. If there is no pth element, return 0.
Example
n = 20
p=3
The factors of 20 in ascending order are {1, 2, 4, 5, 10, 20}. Using 1-based indexing, if p = 3, then 4 is returned. If p >
6, 0 would be returned.
Function Description
105
Returns:
int: the long integer value of the pth integer factor of n or, if there is no factor at that index, then 0 is returned
Constraints
1 ≤ n ≤ 1015
1 ≤ p ≤ 109
Input from stdin will be processed as follows and passed to the function.
The second line contains an integer p, the 1-based index of the factor to return.
Sample Case 0
Sample Input 0
STDIN Function
----- --------
10 → n = 10
3 → p=3
Sample Output 0
Explanation 0
Factoring n = 10 results in {1, 2, 5, 10}. Return the p = 3rd factor, 5, as the answer.
Sample Case 1
Sample Input 1
STDIN Function
----- --------
10 → n = 10
5 → p=5
106
Sample Output 1
Explanation 1
Factoring n = 10 results in {1, 2, 5, 10}. There are only 4 factors and p = 5, therefore 0 is returned as the answer.
Sample Case 2
Sample Input 2
STDIN Function
----- --------
1 → n=1
1 → p=1
Sample Output 2
Explanation 2
Answer:(penalty regime: 0 %)
Reset answer
1 /*
2 * Complete the 'pthFactor' function below.
3 *
4 * The function is expected to return a LONG_INTEGER.
5 * The function accepts following parameters:
6 * 1. LONG_INTEGER n
7 * 2. LONG_INTEGER p
8 */
9
10 long pthFactor(long n, long p)
11 {
12 int count=0;
13 for(long i=1;i<=n;++i)
14 {
15 if(n%i==0)
16 {
17 count++;
18 if(count==p)
19 {
20 return i;
21 }
22 }
23 }
24 return 0;
25 }
Feedback 107
Test Expected Got
Finish review
Skip Quiz navigation
Quiz navigation
108