Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- using namespace std;
- bool palindrom(int x) {
- int y = x, z = 0;
- while (y) {
- z = z * 10 + y % 10;
- y /= 10;
- }
- return x == z;
- }
- int cif(int x) {
- int c = 0;
- while (x) {
- c++;
- x /= 10;
- }
- return c;
- }
- int main() {
- ifstream f("numere.in");
- ofstream g("numere.out");
- int n, x, v[1000], c = -1;
- f >> n;
- for (int i = 1; i <= n; i++) {
- f >> x;
- if (palindrom(x)) {
- g << x << ' ';
- if (cif(x) % 2) {
- c++;
- v[c] = x;
- }
- }
- }
- g << endl;
- n = 1;
- while (n) {
- n = 0;
- for (int i = 0; i <= c - 1; i++) {
- if (v[i] > v[i + 1]) {
- n = 1;
- v[i] = v[i] + v[i + 1];
- v[i + 1] = v[i] - v[i + 1];
- v[i] = v[i] - v[i + 1];
- }
- }
- }
- for (int i = 0; i <= c; i++)
- g << v[i] << ' ';
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement