#4706
Scrieţi definiția completă a subprogramului C++ Peak cu antetul:
void Peak(int a[], int n, int &isPeak, int &poz)
unde a este un tablou unidimensional cu maximum 1000 de numere întregi, n, numărul efectiv de elemente ale tabloului. Dacă vectorul a memorează un șir peak, atunci isPeak va fi egal cu 1, iar poz va reține poziția numărului maxim din a. Dacă vectorul a nu este un șir peak, atunci isPeak va fi egal cu 0, iar poz va reține valoarea 0.
| Problema | Peak | Operații I/O |
peak.in/peak.out
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64865856 | Utilizator | |
| Fișier | peak.cpp | Dimensiune | 327 B |
| Data încărcării | 08 Iunie 2026, 12:13 | Scor/rezultat | Eroare de compilare |
peak.cpp: In function ‘void Peak(int*, int, int&, int&)’: peak.cpp:8:6: error: declaration of ‘int poz’ shadows a parameter 8 | {int poz=1,isPeak=-1; | ^~~ peak.cpp:7:45: note: ‘int& poz’ previously declared here 7 | void Peak(int a[], int n, int &isPeak, int &poz) | ~~~~~^~~ peak.cpp:8:12: error: declaration of ‘int isPeak’ shadows a parameter 8 | {int poz=1,isPeak=-1; | ^~~~~~ peak.cpp:7:32: note: ‘int& isPeak’ previously declared here 7 | void Peak(int a[], int n, int &isPeak, int &poz) | ~~~~~^~~~~~ peak.cpp:9:9: error: ‘i’ was not declared in this scope 9 | for(i=1;i<=n;i++) | ^ peak.cpp:12:5: error: ‘i’ was not declared in this scope 12 | for(i=1;i<=poz;i++) | ^ peak.cpp:16:13: error: expected ‘;’ before ‘poz’ 16 | isPeak=0 | ^ | ; 17 | poz=0;} | ~~~ peak.cpp:19:6: error: ‘i’ was not declared in this scope 19 | {for(i=n;i>=poz;i--) | ^ peak.cpp:26:8: error: return-statement with a value, in function returning ‘void’ [-fpermissive] 26 | return isPeak; | ^~~~~~ peak.cpp:27:8: error: return-statement with a value, in function returning ‘void’ [-fpermissive] 27 | return poz; | ^~~ peak.cpp:29:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 29 | int main() | ^~ peak.cpp:29:9: note: remove parentheses to default-initialize a variable 29 | int main() | ^~ | -- peak.cpp:29:9: note: or replace parentheses with braces to value-initialize a variable peak.cpp:30:1: error: a function-definition is not allowed here before ‘{’ token 30 | { | ^ peak.cpp:39:2: error: expected ‘}’ at end of input 39 | } | ^ peak.cpp:8:1: note: to match this ‘{’ 8 | {int poz=1,isPeak=-1; | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Peak face parte din a doua categorie. Pentru aceste probleme se folosește un program suport, furnizat de propunătorul problemei. 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ă.