#77
Să se scrie un program care să determine ultima cifră pară a unui număr natural citit de la tastatură.
| Problema | UltimaCifraPara | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64237530 | Utilizator | |
| Fișier | ultimacifrapara.cpp | Dimensiune | 225 B |
| Data încărcării | 24 Aprilie 2026, 15:17 | Scor/rezultat | Eroare de compilare |
ultimacifrapara.cpp: In function ‘int main()’: ultimacifrapara.cpp:6:15: error: no match for ‘operator-’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘char’) 6 | if((s - '0') % 2 == 0) { | ~ ^ ~~~ | | | | | char | 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 ultimacifrapara.cpp:1: /usr/include/c++/13/bits/stl_iterator.h:625:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)’ 625 | operator-(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:625:5: note: template argument deduction/substitution failed: ultimacifrapara.cpp:6:17: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’ 6 | if((s - '0') % 2 == 0) { | ^~~ /usr/include/c++/13/bits/stl_iterator.h:1800:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)’ 1800 | operator-(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1800:5: note: template argument deduction/substitution failed: ultimacifrapara.cpp:6:17: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’ 6 | if((s - '0') % 2 == 0) { | ^~~ ultimacifrapara.cpp:7:23: error: no match for ‘operator-’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘char’) 7 | cout << s - '0'; | ~ ^ ~~~ | | | | | char | std::string {aka std::__cxx11::basic_string<char>} /usr/include/c++/13/bits/stl_iterator.h:625:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)’ 625 | operator-(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:625:5: note: template argument deduction/substitution failed: ultimacifrapara.cpp:7:25: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’ 7 | cout << s - '0'; | ^~~ /usr/include/c++/13/bits/stl_iterator.h:1800:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)’ 1800 | operator-(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1800:5: note: template argument deduction/substitution failed: ultimacifrapara.cpp:7:25: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’ 7 | cout << s - '0'; | ^~~ ultimacifrapara.cpp:5:18: warning: unused variable ‘c’ [-Wunused-variable] 5 | for(char c : s) { | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema UltimaCifraPara 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ă.