#4206
Să se scrie o funcție C++ recursivă care să returneze numărul cifrelor divizibile cu 3 ale unui număr natural n transmis ca parametru.
| Problema | CifDiv3Rec | Operații I/O |
cifdiv3rec.in/cifdiv3rec.out
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64461670 | Utilizator | |
| Fișier | cifdiv3rec.cpp | Dimensiune | 297 B |
| Data încărcării | 08 Mai 2026, 09:31 | Scor/rezultat | Eroare de compilare |
cifdiv3rec.cpp:5:2: error: ‘ok’ does not name a type 5 | ok=0; | ^~ cifdiv3rec.cpp: In function ‘int cifdiv3(long long int)’: cifdiv3rec.cpp:9:21: error: ‘ok’ was not declared in this scope 9 | if ( n == 0 && ok ) { | ^~ cifdiv3rec.cpp:11:5: error: expected ‘}’ before ‘else’ 11 | else if ( n == 0 && !ok ) return 1; | ^~~~ cifdiv3rec.cpp:9:26: note: to match this ‘{’ 9 | if ( n == 0 && ok ) { | ^ cifdiv3rec.cpp:12:5: error: ‘ok’ was not declared in this scope 12 | ok = 1; | ^~ cifdiv3rec.cpp: At global scope: cifdiv3rec.cpp:15:6: error: expected unqualified-id before ‘if’ 15 | if(n%10%3==0) | ^~ cifdiv3rec.cpp:19:6: error: expected unqualified-id before ‘else’ 19 | else return cifdiv3(n/10); | ^~~~ cifdiv3rec.cpp:20:6: error: ‘n’ does not name a type 20 | n | ^ cifdiv3rec.cpp:21:2: error: expected declaration before ‘}’ token 21 | } | ^ cifdiv3rec.cpp: In function ‘int main()’: cifdiv3rec.cpp:32:13: error: ‘CifDiv3Rec’ was not declared in this scope; did you mean ‘cifdiv3’? 32 | fout << CifDiv3Rec(n) << "\n"; | ^~~~~~~~~~ | cifdiv3 cifdiv3rec.cpp: In function ‘int cifdiv3(long long int)’: cifdiv3rec.cpp:13:6: warning: control reaches end of non-void function [-Wreturn-type] 13 | } | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema CifDiv3Rec 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ă.