#155
Scrieţi un program care citeşte de la tastatură un şir de cel mult 60 de caractere (litere mici şi mari ale alfabetului englez, cifre, puncte, virgule şi spaţii) şi afişează pe ecran cifra care apare de cele mai multe ori în şirul citit.
Variante Bacalaureat 2009
| Problema | cifmax | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64823017 | Utilizator | |
| Fișier | cifmax.cpp | Dimensiune | 685 B |
| Data încărcării | 03 Iunie 2026, 18:59 | Scor/rezultat | 20 puncte |
cifmax.cpp: In function ‘int main()’: cifmax.cpp:11:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] 11 | for (int i = 0; i < strlen(s); i++) { | ~~^~~~~~~~~~~ cifmax.cpp:13:18: warning: array subscript has type ‘char’ [-Wchar-subscripts] 13 | f[s[i]]++; | ~~~^ cifmax.cpp:17:18: warning: array subscript has type ‘char’ [-Wchar-subscripts] 17 | if (f[s[i]] > max && isdigit(s[i]) != 0) { | ~~~^ cifmax.cpp:18:18: warning: array subscript has type ‘char’ [-Wchar-subscripts] 18 | f[s[i]] = max; | ~~~^ cifmax.cpp:22:19: warning: array subscript has type ‘char’ [-Wchar-subscripts] 22 | if (f[s[i]] == max && isdigit(s[i]) != 0) { | ~~~^ cifmax.cpp:23:25: warning: array subscript has type ‘char’ [-Wchar-subscripts] 23 | a[t] = f[s[i]]; | ~~~^ In file included from /usr/include/c++/13/algorithm:61, from cifmax.cpp:3: In function ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’, inlined from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at /usr/include/c++/13/bits/stl_algo.h:1854:5, inlined from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at /usr/include/c++/13/bits/stl_algo.h:1950:31, inlined from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at /usr/include/c++/13/bits/stl_algo.h:1942:5, inlined from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = int*]’ at /usr/include/c++/13/bits/stl_algo.h:4861:18, inlined from ‘int main()’ at cifmax.cpp:27:10: /usr/include/c++/13/bits/stl_algo.h:1859:32: warning: array subscript 16 is outside array bounds of ‘int [10]’ [-Warray-bounds=] 1859 | std::__insertion_sort(__first, __first + int(_S_threshold), __comp); | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cifmax.cpp: In function ‘int main()’: cifmax.cpp:9:31: note: at offset 64 into object ‘a’ of size 40 9 | int f[10] = {0}, max = -1, a[10] = {0}, t = 0; | ^ cifmax.cpp:18:19: warning: array subscript 48 is above array bounds of ‘int [10]’ [-Warray-bounds=] 18 | f[s[i]] = max; | ~~~~~~^ cifmax.cpp:9:8: note: while referencing ‘f’ 9 | int f[10] = {0}, max = -1, a[10] = {0}, t = 0; | ^
| Test | Timp | Mesaj evaluare | Scor posibil | Scor obținut | ||
|---|---|---|---|---|---|---|
| 1 | 0.001 secunde | OK. | 20 | 20 | Exemplu | |
| 2 | 0.001 secunde | Caught fatal signal 11 | 20 | 0 | ||
| 3 | 0.001 secunde | Raspuns gresit. | 20 | 0 | ||
| 4 | 0.001 secunde | Raspuns gresit. | 20 | 0 | ||
| 5 | 0.001 secunde | Raspuns gresit. | 20 | 0 | ||
| Punctaj total | 20 | |||||
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema cifmax 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ă.