#911
Să se scrie o funcție C++ care primește ca parametri două numere n și k și determină cel mai mare număr care poate fi scris cu k cifre ale lui n. Funcția va întoarce rezultatul prin intermediul unui parametru de ieşire.
| Problema | Cifre6 | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64778757 | Utilizator | |
| Fișier | cifre6.cpp | Dimensiune | 372 B |
| Data încărcării | 29 Mai 2026, 21:25 | Scor/rezultat | Eroare de compilare |
cifre6.cpp: In function ‘int numar(std::string, int, int&)’: cifre6.cpp:7:14: error: no match for ‘operator>’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘int’) 7 | while(n > 0){ | ~ ^ ~ | | | | | int | std::string {aka std::__cxx11::basic_string<char>} In file included from /usr/include/c++/13/string:48, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from cifre6.cpp:1: /usr/include/c++/13/bits/stl_iterator.h:469:5: note: candidate: ‘template<class _Iterator> bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)’ 469 | operator>(const reverse_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:469:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’ 7 | while(n > 0){ | ^ /usr/include/c++/13/bits/stl_iterator.h:514:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)’ 514 | operator>(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:514:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’ 7 | while(n > 0){ | ^ /usr/include/c++/13/bits/stl_iterator.h:1725:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)’ 1725 | operator>(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1725:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’ 7 | while(n > 0){ | ^ /usr/include/c++/13/bits/stl_iterator.h:1784:5: note: candidate: ‘template<class _Iterator> bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)’ 1784 | operator>(const move_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1784:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’ 7 | while(n > 0){ | ^ In file included from /usr/include/c++/13/bits/stl_algobase.h:64, from /usr/include/c++/13/string:51: /usr/include/c++/13/bits/stl_pair.h:848:5: note: candidate: ‘template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)’ 848 | operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/13/bits/stl_pair.h:848:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::pair<_T1, _T2>’ 7 | while(n > 0){ | ^ In file included from /usr/include/c++/13/string:54: /usr/include/c++/13/bits/basic_string.h:3870:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3870 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3870:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘int’ 7 | while(n > 0){ | ^ /usr/include/c++/13/bits/basic_string.h:3884:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)’ 3884 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3884:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: mismatched types ‘const _CharT*’ and ‘int’ 7 | while(n > 0){ | ^ /usr/include/c++/13/bits/basic_string.h:3897:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3897 | operator>(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3897:5: note: template argument deduction/substitution failed: cifre6.cpp:7:16: note: mismatched types ‘const _CharT*’ and ‘std::__cxx11::basic_string<char>’ 7 | while(n > 0){ | ^ cifre6.cpp:8:22: error: no match for ‘operator%’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘int’) 8 | v[cnt++] = n % 10; | ~ ^ ~~ | | | | | int | std::string {aka std::__cxx11::basic_string<char>} cifre6.cpp:9:11: error: no match for ‘operator/=’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘int’) 9 | n /= 10; | ~~^~~~~ cifre6.cpp:20:1: warning: no return statement in function returning non-void [-Wreturn-type] 20 | } | ^ cifre6.cpp: In function ‘int main()’: cifre6.cpp:26:19: error: could not convert ‘x’ from ‘int’ to ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} 26 | numar(x , y , z); | ^ | | | int
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Cifre6 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ă.