#1752
Scrieţi în limbajul C++ definiţia completă a funcţiei recursive nr_aparitii cu următorul antet:
unsigned nr_aparitii(char *sir, char *secventa)
ce returnează numărul de apariţii ale şirului de caractere secventa în şirul sir.
| Problema | nr_aparitii_rec | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64642853 | Utilizator | |
| Fișier | nr_aparitii_rec.cpp | Dimensiune | 227 B |
| Data încărcării | 20 Mai 2026, 09:16 | Scor/rezultat | Eroare de compilare |
nr_aparitii_rec.cpp:6:37: error: expected identifier before ‘*’ token 6 | unsigned nr_aparitii(char *sir,char,*secventa) | ^ nr_aparitii_rec.cpp: In function ‘unsigned int nr_aparitii(char*, char, int*)’: nr_aparitii_rec.cpp:8:14: error: no matching function for call to ‘strstr(char*&, int*&)’ 8 | if(strstr(sir,secventa)==NULL) | ~~~~~~^~~~~~~~~~~~~~ In file included from /usr/include/c++/13/cstring:42, from nr_aparitii_rec.cpp:2: /usr/include/string.h:337:1: note: candidate: ‘char* strstr(char*, const char*)’ 337 | strstr (char *__haystack, const char *__needle) __THROW | ^~~~~~ /usr/include/string.h:337:39: note: no known conversion for argument 2 from ‘int*’ to ‘const char*’ 337 | strstr (char *__haystack, const char *__needle) __THROW | ~~~~~~~~~~~~^~~~~~~~ /usr/include/string.h:343:1: note: candidate: ‘const char* strstr(const char*, const char*)’ 343 | strstr (const char *__haystack, const char *__needle) __THROW | ^~~~~~ /usr/include/string.h:343:45: note: no known conversion for argument 2 from ‘int*’ to ‘const char*’ 343 | strstr (const char *__haystack, const char *__needle) __THROW | ~~~~~~~~~~~~^~~~~~~~ nr_aparitii_rec.cpp:12:23: error: no matching function for call to ‘strstr(char*&, int*&)’ 12 | char *p=strstr(sir,secventa); | ~~~~~~^~~~~~~~~~~~~~ /usr/include/string.h:337:1: note: candidate: ‘char* strstr(char*, const char*)’ 337 | strstr (char *__haystack, const char *__needle) __THROW | ^~~~~~ /usr/include/string.h:337:39: note: no known conversion for argument 2 from ‘int*’ to ‘const char*’ 337 | strstr (char *__haystack, const char *__needle) __THROW | ~~~~~~~~~~~~^~~~~~~~ /usr/include/string.h:343:1: note: candidate: ‘const char* strstr(const char*, const char*)’ 343 | strstr (const char *__haystack, const char *__needle) __THROW | ^~~~~~ /usr/include/string.h:343:45: note: no known conversion for argument 2 from ‘int*’ to ‘const char*’ 343 | strstr (const char *__haystack, const char *__needle) __THROW | ~~~~~~~~~~~~^~~~~~~~ nr_aparitii_rec.cpp:13:36: error: cannot convert ‘int*’ to ‘const char*’ 13 | return 1+nr_aparitii(p+strlen(secventa),secventa); | ^~~~~~~~ | | | int* /usr/include/string.h:407:35: note: initializing argument 1 of ‘size_t strlen(const char*)’ 407 | extern size_t strlen (const char *__s) | ~~~~~~~~~~~~^~~ nr_aparitii_rec.cpp: In function ‘int main()’: nr_aparitii_rec.cpp:23:28: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive] 23 | cout << nr_aparitii(sir, secventa); | ^~~~~~~~ | | | char* nr_aparitii_rec.cpp:23:22: error: too few arguments to function ‘unsigned int nr_aparitii(char*, char, int*)’ 23 | cout << nr_aparitii(sir, secventa); | ~~~~~~~~~~~^~~~~~~~~~~~~~~ nr_aparitii_rec.cpp:6:10: note: declared here 6 | unsigned nr_aparitii(char *sir,char,*secventa) | ^~~~~~~~~~~
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema nr_aparitii_rec 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ă.