eolymp
bolt
Try our new interface for solving problems
Məsələlər

Sadə stek

dərc olunub 08.06.15 17:22:57

Как узнать 1-ый тест?(если возможно). Есть ли на входе отрицательные числа? Есть ли в тестах после n( т.е. после push n) пробел?

dərc olunub 18.01.16 15:27:02

що не так з #2391274 не проходить перший тест

dərc olunub 10.03.24 21:19:53

include <iostream>

include <deque>

using namespace std;

int main() { deque<int> d; string c; while (cin >> c) { if (c == "push") {int n; cin >> n; d.push_back(n); cout << "ok\n";} else if (c == "pop") {if (d.empty()) cout << "error\n"; else {cout << d.back() << "\n"; d.pop_back();}} else if (c == "back") {if (d.empty()) cout << "error\n"; else cout << d.back() << "\n";} else if (c == "size") cout << d.size() << "\n"; else if (c == "clear") {d.clear(); cout << "ok\n";} else if (c == "exit") {cout << "bye\n"; break;} } return 0; }

dərc olunub 28.03.24 17:48:10

// #16369901

include <iostream>

include <stack>

using namespace std; int main() { stack<int> st; int k; string command; while(true) {
cin >> command; if(command=="push") { cin >> k; st.push(k); cout << "ok\n"; } else if(command =="pop") { cout << st.top()<<endl; st.pop(); } else if(command =="back") cout <<st.top()<< endl; else if(command =="size") cout <<st.size()<< endl; else if(command =="exit") { cout <<"bye"<< endl; break; } else if(command=="clear") { cout <<"ok\n"; while(!st.empty()) {st.pop();} }
} return 0; }

dərc olunub 03.04.24 02:17:56

import java.util.*;

public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Stack<String> stack = new Stack<>();

    while (scanner.hasNext()) {
        String str = scanner.next();
        if (str.equals("pop")) {
            System.out.println(stack.pop());
        } else if (str.equals("back")) {
            System.out.println(stack.peek());
        } else if (str.equals("size")) {
            System.out.println(stack.size());
        } else if (str.equals("clear")) {
            System.out.println("ok");
            stack.clear();
        } else if (str.equals("exit")) {
            System.out.println("bye");
            break;
        } else {
            String input = scanner.next();
            System.out.println("ok");
            stack.push(input);
        }
    }
}

}