#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 | #64295235 | Utilizator | |
| Fișier | stiva.cpp | Dimensiune | 1.01 KB |
| Data încărcării | 28 Aprilie 2026, 12:59 | Scor/rezultat | Eroare de compilare |
stiva.cpp:7:8: error: ‘prim’ declared as reference but not initialized 7 | }*p, *&prim; | ^~~~ stiva.cpp: In function ‘void push(nod&, int)’: stiva.cpp:12:16: error: no match for ‘operator=’ (operand types are ‘nod’ and ‘nod*’) 12 | { prim=new nod; | ^~~ stiva.cpp:4:8: note: candidate: ‘nod& nod::operator=(const nod&)’ 4 | struct nod{ | ^~~ stiva.cpp:4:8: note: no known conversion for argument 1 from ‘nod*’ to ‘const nod&’ stiva.cpp:4:8: note: candidate: ‘nod& nod::operator=(nod&&)’ stiva.cpp:4:8: note: no known conversion for argument 1 from ‘nod*’ to ‘nod&&’ stiva.cpp:13:9: error: base operand of ‘->’ has non-pointer type ‘nod’ 13 | prim->info=x; | ^~ stiva.cpp:14:9: error: base operand of ‘->’ has non-pointer type ‘nod’ 14 | prim->adr=NULL; | ^~ stiva.cpp:16:1: error: ‘else’ without a previous ‘if’ 16 | else | ^~~~ stiva.cpp:20:12: error: cannot convert ‘nod’ to ‘nod*’ in assignment 20 | p->adr=prim; | ^~~~ | | | nod stiva.cpp:21:10: error: no match for ‘operator=’ (operand types are ‘nod’ and ‘nod*’) 21 | prim=p; | ^ stiva.cpp:4:8: note: candidate: ‘nod& nod::operator=(const nod&)’ 4 | struct nod{ | ^~~ stiva.cpp:4:8: note: no known conversion for argument 1 from ‘nod*’ to ‘const nod&’ stiva.cpp:4:8: note: candidate: ‘nod& nod::operator=(nod&&)’ stiva.cpp:4:8: note: no known conversion for argument 1 from ‘nod*’ to ‘nod&&’ stiva.cpp: In function ‘void top(nod*)’: stiva.cpp:36:18: error: invalid initialization of reference of type ‘nod&’ from expression of type ‘nod*’ 36 | push(prim, x); | ^~~~ stiva.cpp:10:15: note: in passing argument 1 of ‘void push(nod&, int)’ 10 | void push(nod&prim, int x) | ~~~~^~~~ stiva.cpp:40:12: error: ‘pop’ was not declared in this scope; did you mean ‘op’? 40 | pop (prim); | ^~~ | op stiva.cpp:44:8: error: return-statement with a value, in function returning ‘void’ [-fpermissive] 44 | return 0; | ^ stiva.cpp: In function ‘int main()’: stiva.cpp:54:9: error: ‘in’ was not declared in this scope; did you mean ‘i’? 54 | in>>op; | ^~ | i stiva.cpp:58:18: error: invalid initialization of reference of type ‘nod&’ from expression of type ‘nod*’ 58 | push(prim, x); | ^~~~ stiva.cpp:10:15: note: in passing argument 1 of ‘void push(nod&, int)’ 10 | void push(nod&prim, int x) | ~~~~^~~~ stiva.cpp:62:13: error: ‘pop’ was not declared in this scope; did you mean ‘op’? 62 | pop(prim); | ^~~ | op
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ă.