0% found this document useful (0 votes)
42 views6 pages

Moni CSE Lab Report

Uploaded by

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

Moni CSE Lab Report

Uploaded by

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

Southeast University, Bangladesh

School of Science and Engineering


Department of Computer Science and Engineering

Course Code : CSE162

Course Title : Programming Language I Lab

Lab Report
Submitted By
Name : Monjurul Haque Moni

Batch : CSE66

Student Code : 2024000000038

Section : 4
Semester : Summer 2024

Submitted To

Tashreef Muhammad
Lecturer, Dept. of CSE,
Southeast University, Bangladesh
Table of Contents
Problem 01: 1
Problem 02: 2
Problem 03: 3
Problem 04: 4
Problem 01:
Problem Link:
Team

Solution Approach:

The solution approach involves reading the number of problems, `n`, and
then for each problem, we gather the confidence of three friends (Petya,
Vasya, and Tonya) in solving it. Each friend’s opinion is represented as
either a `1` (confident) or `0` (not confident). For each problem, the code
calculates the sum of these three values. If the sum is `2` or more, this
indicates that at least two of the three friends are confident about solving the
problem, so the friends will implement a solution for it. The code keeps a
count of such problems. Finally, after all problems have been evaluated, the
code outputs the count, which represents the number of problems the friends
will actually solve. This approach is efficient and meets the problem
requirements, as it processes each problem in constant time.

Solution Code:
#include <stdio.h>

int main() {
int n, count = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int p, v, t;
scanf("%d %d %d", &p, &v, &t);

if (p + v + t >= 2) {
count++;
}
}

printf("%d\n", count);

return 0;
}
Problem 02:
Problem Link:
Domino piling

Solution Approach:
The approach to solving this problem involves calculating the total area of
the \( M \times N \) board, which represents the number of individual squares
available. Since each domino covers two squares, the maximum number of
dominoes we can place on the board is simply the number of squares divided
by two. This is because each domino needs exactly two adjacent squares, and
we aim to maximize their use without overlap. Therefore, by dividing the
total number of squares by two, we determine the maximum number of
dominoes that can fit on the board while satisfying all given conditions.
Finally, we print this number as the result. This approach is efficient, using
basic arithmetic operations, and guarantees the correct answer based on the
area of the board.

Solution Code:

#include <stdio.h>

int main() {
int M, N;
scanf("%d %d", &M, &N);
int total_squares = M * N;
int max_dominoes = total_squares / 2;
printf("%d\n", max_dominoes);

return 0;
}
Problem 03:
Problem Link:
In Search of an Easy Problem

Solution Approach:
To solve this problem, we start by reading the integer `n`, which represents
the number of people giving their opinions on the problem. For each opinion,
we read an integer, where `0` means the person thinks the problem is easy,
and `1` means the person thinks it is hard. The goal is to determine if at least
one person finds the problem hard; if so, the problem should be labeled as
"HARD." To do this, we initialize a variable (`isHard`) to track whether
anyone thinks the problem is hard. As we loop through the opinions, we
check if any opinion is `1`. If a `1` is found, we set `isHard` to `1` and can
stop further checks because the result is already determined. After the loop,
if `isHard` is `1`, we print "HARD"; otherwise, we print "EASY." This
approach is efficient because it stops checking as soon as a hard opinion is
detected, ensuring minimal processing.

Solution Code:
#include <stdio.h>

int main() {
int n;
scanf("%d", &n);
int opinion;
int isHard = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &opinion);
if (opinion == 1) {
isHard = 1;
}
}
if (isHard) {
printf("HARD\n");
} else {
printf("EASY\n");
}

return 0;
}
Problem 04:
Problem Link:
Trick or Treat

Solution Approach:
The solution involves first initializing an array, `hasSnack`, to keep
track of which Snukes have snacks, where each element represents
whether a specific Snuke has a snack (with `0` meaning they have
none). For each snack type, we read the number of Snukes who
have that snack, and then mark those specific Snukes in the
`hasSnack` array by setting their value to `1`. Once all snack
distributions have been recorded, we count the number of Snukes
who still have a `0` in the `hasSnack` array, meaning they don’t
have any snacks. This count gives us the number of Snukes who
will fall victim to Takahashi’s mischief. Finally, we output this
count. This approach efficiently tracks and counts the snackless
Snukes using basic array operations.

Solution Code:

#include <stdio.h>
int main() {
int N, K;
scanf("%d %d", &N, &K);
int hasSnack[N + 1];
for (int i = 1; i <= N; i++)
{hasSnack[i] = 0; }
for (int i = 1; i <= K; i++)
{int d;
scanf("%d", &d);
for (int j = 0; j < d; j++)
{int snukeIndex;
scanf("%d", &snukeIndex);
hasSnack[snukeIndex] = 1; }}
int countWithoutSnacks = 0;
for (int i = 1; i <= N; i++)
{if (hasSnack[i] == 0) {
countWithoutSnacks++;}}
printf("%d\n", countWithoutSnacks);
return 0;}

You might also like