Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 3.3
Student Name: Nikita UID: 21BCS2785
Branch:BE-CSE Section/Group: IoT-26B
Semester:5 Date of Performance:12-10-2023
Subject Name: Advance Programming Lab
Subject Code: 21CSP-314

1. Aim:
1.WAP to Marc’s Cake walk
2.WAP to solve grid Challenge
2. 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

3. Script and Output:


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);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

return 0;
}

Output:-

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:-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like