Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int startNum, endNum;
- cin >> startNum >> endNum;
- for (int i = startNum; i <= endNum; i++) {
- int odd = 0, even = 0, digit = i;
- for (int x = 0; x < 6; x++) {
- if (x % 2 == 0) {
- even += digit % 10;
- }
- else {
- odd += digit % 10;
- }
- digit /= 10;
- }
- if (odd == even) {
- cout << i << " ";
- }
- }
- return 0;
- }
- РЕШЕНИЕ С to_string():
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int startNum, endNum;
- cin >> startNum >> endNum;
- for (int i = startNum; i <= endNum; i++) {
- int odd = 0, even = 0, digit = 0;
- string current = to_string(i);
- for (int x = 0; x < current.length(); x++) {
- int digit = (int)(current[x]);
- if (x % 2 == 0) {
- even += digit;
- }
- else {
- odd += digit;
- }
- }
- if (odd == even) {
- cout << i << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement