0% found this document useful (0 votes)
36 views3 pages

Computer Science & Engineering: Department of

1. The document describes two programming experiments. The first involves calculating the distance a person would need to walk to burn calories from eating cupcakes. The second rearranges characters in a grid such that each row is alphabetized and checks if columns are also alphabetized. 2. Two programs were written - one to solve the calorie burning problem and sort calories from highest to lowest. The second rearranges characters in each row of a grid and checks if columns are also in alphabetical order. 3. Key learning outcomes were understanding calorie balance, rearranging grid elements, and alphabetizing rows of a character grid.
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)
36 views3 pages

Computer Science & Engineering: Department of

1. The document describes two programming experiments. The first involves calculating the distance a person would need to walk to burn calories from eating cupcakes. The second rearranges characters in a grid such that each row is alphabetized and checks if columns are also alphabetized. 2. Two programs were written - one to solve the calorie burning problem and sort calories from highest to lowest. The second rearranges characters in each row of a grid and checks if columns are also in alphabetical order. 3. Key learning outcomes were understanding calorie balance, rearranging grid elements, and alphabetizing rows of a character grid.
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/ 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

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

Script and code:


Program 1:-
#include <bits/stdc++.h> using
namespace std;
int main(){ int n; cin
>> n;
vector<int> calories(n);
for(int calories_i = 0;
calories_i < n;
calories_i++){ cin >>
calories[calories_i];
} sort(calories.begin(),calories.end());
reverse(calories.begin(),calories.end()); long
long temp=1,ans=0;
for(int i=0;i<n;i++)
{ ans+=calories[i]*temp; temp*=2;
} printf("%lld\n",ans); return 0;
}

Name: Samarth Maheshwari UID:21BCS10260


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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

Name: Samarth Maheshwari UID:21BCS10260


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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.

Name: Samarth Maheshwari UID:21BCS10260

You might also like