0% found this document useful (0 votes)
4 views9 pages

Python Code Snippets

The document contains multiple C++ programs that perform various tasks, including calculating the length of the longest palindromic subsequence, managing different operational modes, determining travel durations based on road lengths, implementing topological sorting for a directed graph, managing stock levels, and calculating discounts based on total purchases. Each program reads input, processes data, and outputs results accordingly. The code snippets are structured to demonstrate different programming concepts and algorithms.

Uploaded by

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

Python Code Snippets

The document contains multiple C++ programs that perform various tasks, including calculating the length of the longest palindromic subsequence, managing different operational modes, determining travel durations based on road lengths, implementing topological sorting for a directed graph, managing stock levels, and calculating discounts based on total purchases. Each program reads input, processes data, and outputs results accordingly. The code snippets are structured to demonstrate different programming concepts and algorithms.

Uploaded by

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

// You are using GCC

//Zeren is exploring

#include <iostream>

using namespace std;

int main() {

int n;

cin >> n;

int arr[100], rev[100];

for (int i = 0; i < n; i++) {

cin >> arr[i];

rev[n - 1 - i] = arr[i];

int dp[101][101] = {0};

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= n; j++) {

if (arr[i - 1] == rev[j - 1])

dp[i][j] = 1 + dp[i - 1][j - 1];

else

dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

}
cout << "Length of Longest Palindromic Subsequence: " << dp[n][n] << endl;

return 0;

// You are using GCC

//Mira is programming

#include <iostream>

using namespace std;

int main() {

int modeCode;

cin >> modeCode;

switch (modeCode) {

case 1:

cout << "Idle Mode - Waiting";

break;

case 2:

cout << "Exploration Mode - Searching";

break;

case 3:

cout << "Defense Mode - Alert";

break;
case 4:

cout << "Attack Mode - Engage";

break;

case 5:

cout << "Repair Mode - Self Check";

break;

case 6:

cout << "Stealth Mode - Hidden";

break;

case 7:

cout << "Power Saving Mode - Low Battery";

break;

case 8:

cout << "Shutdown Mode - Power Off";

break;

default:

cout << "Unknown Mode";

return 0;

// You are using GCC

//Nia is designing
#include <iostream>

using namespace std;

int main() {

int n, e, s, w;

cin >> n >> e >> s >> w;

int roads[4] = {n, e, s, w};

int durations[4];

for (int i = 0; i < 4; i++) {

if (roads[i] <= 10)

durations[i] = 15;

else if (roads[i] <= 30)

durations[i] = 30;

else if (roads[i] <= 60)

durations[i] = 45;

else

durations[i] = 60;

cout << durations[0] << " " << durations[1] << " "

<< durations[2] << " " << durations[3];

return 0;

}
// You are using GCC

//You are the lead

#include <iostream>

using namespace std;

int main() {

int n, m;

cin >> n >> m;

int adj[100][100] = {0};

int indegree[100] = {0};

for (int i = 0; i < m; i++) {

int a, b;

cin >> a >> b;

adj[a][b] = 1;

indegree[b]++;

int queue[100], front = 0, rear = 0;

for (int i = 1; i <= n; i++) {

if (indegree[i] == 0)

queue[rear++] = i;
}

int count = 0;

int order[100];

while (front < rear) {

int u = queue[front++];

order[count++] = u;

for (int v = 1; v <= n; v++) {

if (adj[u][v]) {

indegree[v]--;

if (indegree[v] == 0)

queue[rear++] = v;

if (count != n) {

cout << "IMPOSSIBLE" << endl;

} else {

cout << "Order ";

for (int i = 0; i < count; i++)

cout << order[i] << " ";

cout << endl;

}
}

// You are using GCC

//Zara manages an

#include <iostream>

using namespace std;

int main() {

int q;

cin >> q;

while (q != 0) {

if (q < 50)

cout << "Replenish Required" << endl;

else if (q <= 200)

cout << "Stock Sufficient" << endl;

else

cout << "Overstock Warning" << endl;

cin >> q;

}
return 0;

// You are using GCC

//Anaa owns a

#include <iostream>

using namespace std;

int main() {

int p1, p2, p3;

cin >> p1 >> p2 >> p3;

int total = p1 + p2 + p3;

if (total >= 300) {

cout << "High Discount";

} else if (total >= 200) {

cout << "Medium Discount";

} else if (total >= 100) {

cout << "Low Discount";

} else {

cout << "No Discount";

}
return 0;

You might also like