#875
Să se scrie un program care gestionează o stivă de numere întregi. Inițial stiva este vidă. Programul va citi de la tastatură o listă de operații, care pot fi:
push X – adaugă valoarea întreagă X pe stivă;pop – elimină elementul din vârful stivei;top – afișează elementul din vârful stivei.Programul va realiza asupra stivei operațiile citite, în ordine. Afișările se fac pe ecran, câte o valoare pe linie.
| Problema | Stiva | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #63720661 | Utilizator | |
| Fișier | stiva.cpp | Dimensiune | 482 B |
| Data încărcării | 16 Martie 2026, 17:14 | Scor/rezultat | Eroare de compilare |
stiva.cpp:1:20: warning: extra tokens at end of #include directive [enabled by default] #include <iostream>#include <cstring>#include <stack>using namespace std; ^ stiva.cpp:1:47: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix] #include <iostream>#include <cstring>#include <stack>using namespace std; ^ stiva.cpp:2:1: error: 'stack' does not name a type stack <int>stiva;char s[5]; ^ stiva.cpp: In function 'int main()': stiva.cpp:5:5: error: 'cin' was not declared in this scope cin>>n; ^ stiva.cpp:5:5: note: suggested alternative: In file included from stiva.cpp:1:0: /usr/include/c++/4.8/iostream:60:18: note: 'std::cin' extern istream cin; /// Linked to standard input ^ stiva.cpp:8:28: error: 'strcmp' was not declared in this scope if(strcmp(s, "push")==0){ ^ stiva.cpp:11:13: error: 'stiva' was not declared in this scope stiva.push(x); ^ stiva.cpp:12:36: error: 'strcmp' was not declared in this scope } if(strcmp(s, "pop")==0 && !stiva.empty()) ^ stiva.cpp:12:45: error: 'stiva' was not declared in this scope } if(strcmp(s, "pop")==0 && !stiva.empty()) ^ stiva.cpp:14:27: error: 'strcmp' was not declared in this scope if(strcmp(s, "top")==0 && !stiva.empty()) ^ stiva.cpp:14:36: error: 'stiva' was not declared in this scope if(strcmp(s, "top")==0 && !stiva.empty()) ^ stiva.cpp:15:13: error: 'cout' was not declared in this scope cout<<stiva.top()<<endl; ^ stiva.cpp:15:13: note: suggested alternative: In file included from stiva.cpp:1:0: /usr/include/c++/4.8/iostream:61:18: note: 'std::cout' extern ostream cout; /// Linked to standard output ^ stiva.cpp:15:32: error: 'endl' was not declared in this scope cout<<stiva.top()<<endl; ^ stiva.cpp:15:32: note: suggested alternative: In file included from /usr/include/c++/4.8/iostream:39:0, from stiva.cpp:1: /usr/include/c++/4.8/ostream:564:5: note: 'std::endl' endl(basic_ostream<_CharT, _Traits>& __os) ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Stiva face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.