uk
Feedback

Не попадись на ботовода! Telemetrio знаходить і позначає такі канали мітками 👉 Хочеш бачити мітку, оформляй підписку

Infosys | IBM | Accenture Exam Help

Infosys | IBM | Accenture Exam Help

Відкрити в Telegram

Any Online Assessment Help Available ✅ Admin - @Codehelpdesk 😇 ⭕ Daily Jobs and Internships Updates ⭕ Any Online Assesment Help Available ⭕ IT/ Non-IT Job Updates

Показати більше
4 685
Підписники
Немає даних24 години
-57 днів
+930 днів
Архів дописів
import java.util.*;

public class LoopMaster {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numberOfCommands = Integer.parseInt(scanner.nextLine());
        List<String> commands = new ArrayList<>();
        for (int i = 0; i < numberOfCommands; i++) {
            commands.add(scanner.nextLine().trim());
        }
        processCommands(commands);
    }

    private static void processCommands(List<String> commands) {
        Stack<Integer> loopIterations = new Stack<>();
        Stack<Integer> currentIterations = new Stack<>();
        StringBuilder output = new StringBuilder();
        int commandIndex = 0;

        while (commandIndex < commands.size()) {
            String command = commands.get(commandIndex);
            if (command.startsWith("for")) {
                int times = Integer.parseInt(command.split(" ")[1]);
                loopIterations.push(times);
                currentIterations.push(0);
            } else if (command.equals("do")) {
                // No operation for "do"
            } else if (command.equals("done")) {
                int current = currentIterations.pop() + 1;
                int maxIterations = loopIterations.pop();
                if (current < maxIterations) {
                    loopIterations.push(maxIterations);
                    currentIterations.push(current);
                    commandIndex = findLoopStart(commands, commandIndex);
                    continue;
                }
            } else if (command.startsWith("break")) {
                int breakCondition = Integer.parseInt(command.split(" ")[1]);
                if (currentIterations.peek() + 1 == breakCondition) {
                    loopIterations.pop();
                    currentIterations.pop();
                    commandIndex = findLoopEnd(commands, commandIndex);
                }
            } else if (command.startsWith("continue")) {
                int continueCondition = Integer.parseInt(command.split(" ")[1]);
                if (currentIterations.peek() + 1 == continueCondition) {
                    int maxIterations = loopIterations.peek();
                    int current = currentIterations.pop() + 1;
                    if (current < maxIterations) {
                        currentIterations.push(current);
                        commandIndex = findLoopStart(commands, commandIndex);
                    }
                    continue;
                }
            } else if (command.startsWith("print")) {
                String message = command.substring(command.indexOf("\"") + 1, command.lastIndexOf("\""));
                output.append(message).append("\n");
            }
            commandIndex++;
        }
        System.out.print(output.toString());
    }

    private static int findLoopStart(List<String> commands, int currentIndex) {
        int nestedLoops = 0;
        for (int i = currentIndex - 1; i >= 0; i--) {
            if (commands.get(i).equals("done")) {
                nestedLoops++;
            } else if (commands.get(i).equals("do")) {
                if (nestedLoops == 0) {
                    return i;
                }
                nestedLoops--;
            }
        }
        return 0;
    }

    private static int findLoopEnd(List<String> commands, int currentIndex) {
        int nestedLoops = 0;
        for (int i = currentIndex + 1; i < commands.size(); i++) {
            if (commands.get(i).equals("do")) {
                nestedLoops++;
            } else if (commands.get(i).equals("done")) {
                if (nestedLoops == 0) {
                    return i;
                }
                nestedLoops--;
            }
        }
        return commands.size();
    }
}
Loop Master - Codevita
30 лист 2024, 00:48

#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; vector<vector<int>> z(x, vector<int>(y)); for (int i = 0; i < x; ++i) { for (int j = 0; j < y; ++j) { cin >> z[i][j]; } } int w; cin >> w; map<int, vector<pair<int, int>>> a; set<int> b; for (int i = 0; i < x; ++i) { for (int j = 0; j < y; ++j) { int c = z[i][j]; a[c].emplace_back(i, j); b.insert(c); } } set<int> d; for (int i = 0; i < x; ++i) { vector<int> e; for (int j = 0; j < y; ++j) { if (z[i][j] == w) { e.push_back(j); } } if (!e.empty()) { int f = *max_element(e.begin(), e.end()); for (int j = f + 1; j < y; ++j) { int g = z[i][j]; if (g != w) { d.insert(g); } } } } set<int> h = b; d.erase(w); int i = 0; for (auto j = d.begin(); j != d.end(); ++j) { if (h.find(*j) != h.end()) { h.erase(*j); i++; } } auto k = [&](const set<int>& l) -> set<int> { set<int> m; for (auto& n : l) { for (auto& [o, p] : a[n]) { if (o == x - 1) { m.insert(n); break; } } } queue<int> q; for (auto& r : m) { q.push(r); } while (!q.empty()) { int s = q.front(); q.pop(); for (auto& t : l) { if (m.find(t) != m.end()) continue; bool u = false; for (auto& [v, w] : a[t]) { if (v + 1 < x) { int x = z[v + 1][w]; if (m.find(x) != m.end()) { u = true; break; } } } if (u) { m.insert(t); q.push(t); } } } return m; }; while (true) { set<int> y = k(h); set<int> z; for (auto& aa : h) { if (y.find(aa) == y.end()) { z.insert(aa); } } if (z.empty()) break; for (auto& bb : z) { h.erase(bb); i++; } } cout << i; return 0; } Block Extraction - Codevita ✅
30 лист 2024, 00:47

Equal puzzle ✅
Equal puzzle ✅
30 лист 2024, 00:44

Dessert Queen - Codevita ✅
Dessert Queen - Codevita ✅
30 лист 2024, 00:43

Shannon Circuit ✅
Shannon Circuit ✅
30 лист 2024, 00:23

14 segments - TCS Codevita ✅
14 segments - TCS Codevita ✅
30 лист 2024, 00:18

Count Press - TCS Codevita ✅
Count Press - TCS Codevita ✅
30 лист 2024, 00:15

Those who need free codes Please give a ❤️ I’ll upload more codes ✅
30 лист 2024, 00:00

Office Rostering - TCS Codevita ✅
Office Rostering - TCS Codevita ✅
29 лист 2024, 23:56

Toggle Challenge - TCS Codevits ✅
Toggle Challenge - TCS Codevits ✅
29 лист 2024, 23:54

Cart - TCS Codevita ✅
Cart - TCS Codevita ✅
29 лист 2024, 23:53

String Obsession - TCS Codevita
String Obsession - TCS Codevita
29 лист 2024, 08:28

🔴Any OA Help Available Dm @Codehelpdesk ⭐
29 лист 2024, 08:26

🔴Zscalar Help Available 🔴 Dm @Codehelpdesk ⭐
28 лист 2024, 09:48

🔴Cotiviti Help Done🔴 40/40 MCQs ✅ For any exam help Dm @Codehelpdesk ⭐
+1
🔴Cotiviti Help Done🔴 40/40 MCQs ✅ For any exam help Dm @Codehelpdesk ⭐
27 лист 2024, 07:31

🔴Morning Star Help Done🔴 4/4 Sections Done ✅ For any exam help Dm @Codehelpdesk ⭐
+1
🔴Morning Star Help Done🔴 4/4 Sections Done ✅ For any exam help Dm @Codehelpdesk ⭐
27 лист 2024, 02:13

🔴Morning Star Help Available 🔴 100% Clearance Guarantee ✅ Dm @Codehelpdesk ⭐
27 лист 2024, 00:06

🔴T-Machines Help Done 🔴 50/50 MCQs ✅ For any exam help Dm @Codehelpdesk ⭐
🔴T-Machines Help Done 🔴 50/50 MCQs ✅ For any exam help Dm @Codehelpdesk ⭐
27 лист 2024, 00:05

🔴Netcore around 2 Help Done🔴 2/2 Codes Done ✅ All test cases passed ✅ For any exam help Dm @Codehelpdesk ⭐
+1
🔴Netcore around 2 Help Done🔴 2/2 Codes Done ✅ All test cases passed ✅ For any exam help Dm @Codehelpdesk ⭐
26 лист 2024, 08:53

🔴Barclays Hiring🔴 2025 Batch Apply link 🔗 https://search.jobs.barclays/job/-/-/13015/73381614864
🔴Barclays Hiring🔴 2025 Batch Apply link 🔗 https://search.jobs.barclays/job/-/-/13015/73381614864
25 лист 2024, 06:23

Ми використовуємо файли cookie для покращення вашого досвіду перегляду.
Натиснувши «Прийняти все», ви погоджуєтеся на політику використання файлів cookie.