#875
Stiva
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 | #53861139 | Utilizator | |
Fișier | stiva.cpp | Dimensiune | 1.82 KB |
Data încărcării | 13 Noiembrie 2024, 13:28 | Scor / rezultat | Eroare de compilare |
stiva.cpp:1:7: error: expected nested-name-specifier before 'System' using System; ^ stiva.cpp:1:7: error: 'System' has not been declared stiva.cpp:2:7: error: expected nested-name-specifier before 'System' using System.Collections.Generic; ^ stiva.cpp:2:7: error: 'System' has not been declared stiva.cpp:2:13: error: expected ';' before '.' token using System.Collections.Generic; ^ stiva.cpp:2:13: error: expected unqualified-id before '.' token stiva.cpp:3:7: error: expected nested-name-specifier before 'System' using System.Linq; ^ stiva.cpp:3:7: error: 'System' has not been declared stiva.cpp:3:13: error: expected ';' before '.' token using System.Linq; ^ stiva.cpp:3:13: error: expected unqualified-id before '.' token stiva.cpp:4:7: error: expected nested-name-specifier before 'System' using System.Text; ^ stiva.cpp:4:7: error: 'System' has not been declared stiva.cpp:4:13: error: expected ';' before '.' token using System.Text; ^ stiva.cpp:4:13: error: expected unqualified-id before '.' token stiva.cpp:5:7: error: expected nested-name-specifier before 'System' using System.Threading.Tasks; ^ stiva.cpp:5:7: error: 'System' has not been declared stiva.cpp:5:13: error: expected ';' before '.' token using System.Threading.Tasks; ^ stiva.cpp:5:13: error: expected unqualified-id before '.' token stiva.cpp:9:11: error: 'Nod' is not a class template class Nod<T> ^ stiva.cpp:9:15: error: 'T' was not declared in this scope class Nod<T> ^ stiva.cpp:11:16: error: expected ':' before 'T' public T info; ^ stiva.cpp:11:16: error: 'T' does not name a type stiva.cpp:12:16: error: expected ':' before 'Nod' public Nod<T> leg; ^ stiva.cpp:12:16: error: 'p26_ClaseTemplate::Nod' is not a template stiva.cpp:12:20: error: 'T' was not declared in this scope public Nod<T> leg; ^ stiva.cpp:12:23: error: field 'leg' has incomplete type public Nod<T> leg; ^ stiva.cpp:13:16: error: expected ':' before 'Nod' public Nod(T x) ^ stiva.cpp:13:22: error: expected ')' before 'x' public Nod(T x) ^ stiva.cpp:18:5: error: expected ';' after class definition } ^ stiva.cpp:20:11: error: 'Stiva' is not a class template class Stiva<T> ^ stiva.cpp:20:17: error: 'T' was not declared in this scope class Stiva<T> ^ stiva.cpp:22:17: error: expected ':' before 'Nod' private Nod<T> top; ^ stiva.cpp:22:17: error: 'p26_ClaseTemplate::Nod' is not a template stiva.cpp:22:21: error: 'T' was not declared in this scope private Nod<T> top; ^ stiva.cpp:23:17: error: expected ':' before 'int' private int n; // numarul de elemente ^ stiva.cpp:25:16: error: expected ':' before 'Stiva' public Stiva() ^ stiva.cpp:31:16: error: expected ':' before 'void' public void Push(T x) ^ stiva.cpp:31:26: error: 'T' has not been declared public void Push(T x) ^ stiva.cpp:39:16: error: expected ':' before 'void' public void Pop() ^ stiva.cpp:48:16: error: expected ':' before 'T' public T Top() ^ stiva.cpp:48:16: error: 'T' does not name a type stiva.cpp:53:16: error: expected ':' before 'bool' public bool Empty() ^ stiva.cpp:58:16: error: expected ':' before 'void' public void Init() ^ stiva.cpp:63:16: error: expected ':' before 'int' public int Count ^ stiva.cpp:66:9: error: expected ';' at end of member declaration } ^ stiva.cpp:67:5: error: expected ';' after class definition } ^ stiva.cpp:65:13: error: 'get' was not declared in this scope get { return n; } ^ stiva.cpp:65:17: error: expected '}' before '{' token get { return n; } ^ stiva.cpp:65:17: error: cannot convert '<brace-enclosed initializer list>' to 'int' in initialization stiva.cpp:65:17: error: expected ';' before '{' token stiva.cpp: In member function 'void p26_ClaseTemplate::Stiva::Push(int)': stiva.cpp:33:13: error: 'p26_ClaseTemplate::Nod' is not a template Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:17: error: 'T' was not declared in this scope Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:28: error: 'p26_ClaseTemplate::Nod' is not a template Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:32: error: the value of 'T' is not usable in a constant expression Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:17: note: 'T' was not declared 'constexpr' Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:36: error: no matching function for call to 'p26_ClaseTemplate::Nod::Nod(int&)' Nod<T> p = new Nod<T>(x); ^ stiva.cpp:33:36: note: candidates are: stiva.cpp:9:11: note: constexpr p26_ClaseTemplate::Nod::Nod() class Nod<T> ^ stiva.cpp:9:11: note: candidate expects 0 arguments, 1 provided stiva.cpp:9:11: note: constexpr p26_ClaseTemplate::Nod::Nod(const p26_ClaseTemplate::Nod&) stiva.cpp:9:11: note: no known conversion for argument 1 from 'int' to 'const p26_ClaseTemplate::Nod&' stiva.cpp:9:11: note: constexpr p26_ClaseTemplate::Nod::Nod(p26_ClaseTemplate::Nod&&) stiva.cpp:9:11: note: no known conversion for argument 1 from 'int' to 'p26_ClaseTemplate::Nod&&' stiva.cpp:34:15: error: 'class p26_ClaseTemplate::Nod' has no member named 'leg' p.leg = top; ^ stiva.cpp: In member function 'void p26_ClaseTemplate::Stiva::Pop()': stiva.cpp:41:24: error: 'null' was not declared in this scope if (top == null) return; ^ stiva.cpp:42:13: error: 'p26_ClaseTemplate::Nod' is not a template Nod<T> p = top; ^ stiva.cpp:42:17: error: 'T' was not declared in this scope Nod<T> p = top; ^ stiva.cpp:43:23: error: 'class p26_ClaseTemplate::Nod' has no member named 'leg' top = top.leg; ^ stiva.cpp:44:17: error: 'null' was not declared in this scope p = null; ^ stiva.cpp: In member function 'bool p26_ClaseTemplate::Stiva::Empty()': stiva.cpp:55:27: error: 'null' was not declared in this scope return top == null; ^ stiva.cpp: In member function 'void p26_ClaseTemplate::Stiva::Init()': stiva.cpp:60:19: error: 'null' was not declared in this scope top = null; ^ stiva.cpp: At global scope: stiva.cpp:71:26: error: 'string' has not been declared static void Main(string[] args) ^ stiva.cpp:71:35: error: expected ',' or '...' before 'args' static void Main(string[] args) ^ stiva.cpp:87:5: error: expected ';' after class definition } ^ stiva.cpp: In static member function 'static void p26_ClaseTemplate::Program::Main(int*)': stiva.cpp:74:17: error: expected primary-expression before 'int' n = int.Parse(Console.ReadLine()); ^ stiva.cpp:74:17: error: expected ';' before 'int' stiva.cpp:75:13: error: 'p26_ClaseTemplate::Stiva' is not a template Stiva<int> st = new Stiva<int>(); ^ stiva.cpp:75:33: error: 'p26_ClaseTemplate::Stiva' is not a template Stiva<int> st = new Stiva<int>(); ^ stiva.cpp:75:44: error: conversion from 'p26_ClaseTemplate::Stiva*' to non-scalar type 'p26_ClaseTemplate::Stiva' requested Stiva<int> st = new Stiva<int>(); ^ stiva.cpp:78:17: error: 'string' was not declared in this scope string linie = Console.ReadLine(); ^ stiva.cpp:78:24: error: expected ';' before 'linie' string linie = Console.ReadLine(); ^ stiva.cpp:79:24: error: expected primary-expression before ']' token string[] w = linie.Split(new char[] { ' ' }, ^ stiva.cpp:79:26: error: expected ';' before 'w' string[] w = linie.Split(new char[] { ' ' }, ^ stiva.cpp:79:60: error: expected primary-expression before ',' token string[] w = linie.Split(new char[] { ' ' }, ^ stiva.cpp:80:21: error: 'StringSplitOptions' was not declared in this scope StringSplitOptions.RemoveEmptyEntries); ^ stiva.cpp:80:58: error: expected ';' before ')' token StringSplitOptions.RemoveEmptyEntries); ^ stiva.cpp:81:21: error: 'w' was not declared in this scope if (w[0] == "push") ^ stiva.cpp:82:29: error: expected primary-expression before 'int' st.Push(int.Parse(w[1])); ^ stiva.cpp:84:39: error: 'Console' was not declared in this scope else if (!st.Empty()) Console.WriteLine(st.Top()); ^ stiva.cpp:84:60: error: 'class p26_ClaseTemplate::Stiva' has no member named 'Top' else if (!st.Empty()) Console.WriteLine(st.Top()); ^
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ă.