#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 | #64877827 | Utilizator | |
| Fișier | stiva.cpp | Dimensiune | 342 B |
| Data încărcării | 09 Iunie 2026, 09:23 | Scor/rezultat | Eroare de compilare |
stiva.cpp: In function ‘int main()’: stiva.cpp:13:13: error: ‘s’ was not declared in this scope 13 | cin>>s; | ^ stiva.cpp:14:20: error: expected unqualified-id before string constant 14 | if(strcmp(s."push")==0) | ^~~~~~ stiva.cpp:15:14: error: ‘x’ was not declared in this scope 15 | cin>>x; | ^ stiva.cpp:14:8: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 14 | if(strcmp(s."push")==0) | ^~ stiva.cpp:16:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 16 | vf++; | ^~ stiva.cpp:17:16: error: ‘x’ was not declared in this scope 17 | st[vf]=x; | ^ stiva.cpp:19:4: error: ‘else’ without a previous ‘if’ 19 | else if(strcmp(s,"pop")==0) vf--; | ^~~~ stiva.cpp:19:19: error: ‘s’ was not declared in this scope 19 | else if(strcmp(s,"pop")==0) vf--; | ^
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ă.