Ap3 1
Ap3 1
Ap3 1
Experiment 3.1
Student Name: Tanmay Toshniwal UID: 21BCS7091
Branch:BE-CSE Section/Group: IoT-624
Semester:5 Date of Performance:05-10-2023
Subject Name: Advance Programming Lab
Subject Code: 21CSP-314
1. Aim:
1.WAP to construct the array
2.WAP to minima the operation on array
2. Objective:
1. Your goal is to find the number of ways to construct an array such that consecutive positions
contain different values. Specifically, we want to construct an array with elements such that each
element between and , inclusive. We also want the first and last elements of the array to be and .
Given , and , find the number of ways to construct such an array. Since the answer may be large,
only find it modulo
2. Christy is interning at HackerRank. One day she has to distribute some chocolates to her
colleagues. She is biased towards her friends and plans to give them more than the others. One of
the program managers hears of this and tells her to make sure everyone gets the same number.
To make things difficult, she must equalize the number of chocolates in a series of operations.
For each operation, she can give pieces to all but one colleague. Everyone who gets a piece in a
round receives the same number of pieces.
long answer;
if (x == 1) {
answer = (ways[fillSecond][1] * (k - 1)) % MOD;
}
else {
answer = (ways[fillSecond][1] * (k -
2) + ways[fillSecond][0]) % MOD;
}
return answer;
}
int main() {
int n;
int k;
int x;
cin >> n >> k >> x;
long answer = countArray(n, k, x);
cout << answer << endl;
return 0;
}
Output:-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Program 2:-
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
int equal(vector<int> arr) {
vector<int> possibilities(5, 0);
int minimum = *min_element(arr.begin(), arr.end());
string t_temp;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
getline(cin, t_temp);
int t = stoi(ltrim(rtrim(t_temp)));
int n = stoi(ltrim(rtrim(n_temp)));
string arr_temp_temp;
getline(cin, arr_temp_temp);
vector<int> arr(n);
arr[i] = arr_item;
}
int result = equal(arr);
Output:-