bool IsPalindrome(int n)
{
int s = 0, m = n;
do
s = s*10+m % 10;
while(m /= 10);
return s == n;
}
void Sort(int* a, const int* pal, int np)
{
for (int i = 0; i < np - 1; ++i)
{
for (int j = np - 2; j >= i; --j)
{
if (a[pal[j]] > a[pal[j + 1]])
{
std::swap(a[pal[j]], a[pal[j + 1]]);
}
}
}
}
void main()
{
FILE *f = fopen("file.txt", "r");
int s, *a, *pa, s1 = 0;
fscanf(f, "%d", &s);
a = (int*)malloc(sizeof(int)* s);
pa = (int*)malloc(sizeof(int)* s);//массив для палиндромов
for (int i = 0; i < s; ++i)
{
fscanf(f, "%d", &a[i]);
if (IsPalindrome(a[i]))
pa[s1++] = i;
}
Sort(a, pa, s1);
for (int i = 0; i < s; ++i)
std::cout << a[i] << "\n";
fclose(f);
getchar();
}
Comments