Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"stdafx.h"
- #include<iostream>
- #include<stdio.h>
- #include <string.h>
- const int M = 100, L = 255;
- bool sym(char s[])
- {
- int i, n = strlen(s) / 2;
- if (strlen(s) % 2 == 0)
- {
- for (i = 0; i < n; i++)
- if (s[n - i - 1] != s[n + i]) return false;
- }
- else
- {
- for (i = 1; i <= n; i++)
- if (s[n - i] != s[n + i]) return false;
- }
- return true;
- }
- void swap(char a[],char b[])
- {
- char c[L];
- strcpy(c, a);
- strcpy(a, b);
- strcpy(b, c);
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- int i, j, k, n, l, t, pause;
- char s[M][L], a[L];
- for (i = 0; i<M; i++)
- {
- gets_s(s[i]);
- if (!*s[i]) break;
- }
- n = i;
- strcpy(a, s[0]);
- for (i = 1; i < n; i++)
- strcat(a, s[i]);
- if (sym(a))
- printf("Palindrome:\n%s\n", a);
- for (i = 0; i < n - 1; i++)
- {
- if (sym(a)) break;
- for (j = i + 1; j <= n - 1; j++)
- {
- swap(s[i], s[j]);
- strcpy(a, s[0]);
- for (k = 1; k < n; k++)
- strcat(a, s[k]);
- printf("%s\n", a);
- if (sym(a))
- {
- printf("Palindrome:\n%s\n", a);
- break;
- }
- swap(s[i], s[j]);
- }
- }
- scanf_s("%i", &pause);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement