Computer Science & Engineering: Department of
Computer Science & Engineering: Department of
Experiment 3.3
Student Name: Samarth Maheshwari UID: 21BCS10260
Branch: BE-CSE Section/Group: IoT-613A
Semester:5 Date: 30-10-2023
Subject Name: Advance Programming Lab Subject Code: 21CSP-314
Aim:
1.WAP to Marc’s Cake walk
2.WAP to solve grid Challenge
Objective:
1. Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie count, and Marc
can walk a distance to expend those calories. If Marc has eaten cupcakes so far, after eating a
cupcake with calories he must walk at least miles to maintain his weight.
2. Given a square grid of characters in the range ascii[a-z], rearrange elements of each row
alphabetically, ascending. Determine if the columns are also in ascending alphabetical order,
top to bottom. Return YES if they are or NO if they are not
Program 2:-
#include <bits/stdc++.h>
using namespace std;
string s[111]; int main()
{ int t; cin >> t;
while (t--) { int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i], sort(s[i].begin(), s[i].end()); bool flag = true;
for (int i = 0;i < n; i++) for (int j = 0; j + 1 < n; j++) if (s[j][i] > s[j + 1][i]) flag =
false;
puts(flag ? "YES" : "NO"); } return 0;
}
Output:
Program 1
Program 2
Learning Outcomes:
• Understand a real-world problem involving the balance between calorie intake and physical
activity.
• Understand the concept of rearranging elements in a grid of characters.
• Learn how to rearrange characters within each row in alphabetical order.