#1598
Coada1
Se consideră C
o coadă de numere naturale, iniţial vidă. Se definesc 2 tipuri de operaţii.
Operaţia 1
: push X
, adaugă elementul X
în coadă. Dacă X
există deja în coadă, se scot toate elementele din coadă, pana la întâlnirea lui, inclusiv X
.
Exemplu: C: 2 4 5 1 6 Push 5 C: 1 6 5 ( s-au scos 2, 4, 5).
Operaţia 2
: query X
, cere afişarea poziţiei elementului X
în coada C
. Dacă elementul nu există în coadă, se afişează -1
.
Exemplu: C: 2 5 1 3 7 Query 1 Răspuns: 3
Problema | Coada1 | Operații I/O |
![]() coada1.in /coada1.out
|
---|---|---|---|
Limita timp | 0.05 secunde | Limita memorie |
Total: 16 MB
/
Stivă 2 MB
|
Id soluție | #58148761 | Utilizator | |
Fișier | coada1.cpp | Dimensiune | 1023 B |
Data încărcării | 16 Mai 2025, 13:45 | Scor / rezultat | Eroare de compilare |
coada1.cpp:4:1: error: 'ifstream' does not name a type ifstream fin ^ coada1.cpp:8:2: error: 'queue' does not name a type queue<int> Q,q; ^ coada1.cpp: In function 'int main()': coada1.cpp:11:6: error: 'cin' was not declared in this scope cin >>n; ^ coada1.cpp:11:6: note: suggested alternative: In file included from coada1.cpp:1:0: /usr/include/c++/4.8/iostream:60:18: note: 'std::cin' extern istream cin; /// Linked to standard input ^ coada1.cpp:15:16: error: 'q' was not declared in this scope while(q.front() !=X && !Q.empty()) ^ coada1.cpp:15:34: error: 'Q' was not declared in this scope while(q.front() !=X && !Q.empty()) ^ coada1.cpp:20:13: error: 'Q' was not declared in this scope if(Q.empty()) ^ coada1.cpp:22:21: error: 'q' was not declared in this scope while (!q.empty()) ^ coada1.cpp:25:17: error: 'q' was not declared in this scope q.pop(); ^ coada1.cpp:26:14: error: expected '}' before 'else' else ^ coada1.cpp:33:14: error: 'fin' was not declared in this scope fin>>X; ^ coada1.cpp:34:21: error: 'Q' was not declared in this scope while (Q.front() !=X && !Q.empty) ^ coada1.cpp:36:14: error: 'q' was not declared in this scope q.push(Q.front ()) ^ coada1.cpp:36:21: error: 'Q' was not declared in this scope q.push(Q.front ()) ^ coada1.cpp:37:14: error: expected ';' before 'Q' Q.pop(); ^ coada1.cpp:39:13: error: 'Q' was not declared in this scope if(Q.empty()) ^ coada1.cpp:41:14: error: 'fout' was not declared in this scope fout -1 << '\n'; ^ coada1.cpp:42:21: error: 'q' was not declared in this scope while(!q.empty()) ^ coada1.cpp: At global scope: coada1.cpp:49:4: error: expected unqualified-id before 'return' return 0; ^ coada1.cpp:50:1: error: expected declaration before '}' token } ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Coada1 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ă.