Advertisement
RadioNurshat

maxpalindrome

Nov 5th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. setlocale(LC_ALL, "RU");
  6. char line[] = "Тимур играет в бравлстарс азаза тимумит";
  7. cout << line << endl << endl;
  8. int max = 0, s = 0, max_i;
  9. for (int i = 0; i < strlen(line); i++)
  10. {
  11. if (line[i] == ' ')
  12. {
  13. if (s > 0) {
  14. bool isLoop = true;
  15. for (int j = i - s; j < i; j++) {
  16. cout << line[i - j - 1] << " " << line[j] << endl;
  17. if (line[i - j - 1] != line[j]) {
  18. isLoop = false;
  19. }
  20. }
  21. if (isLoop) {
  22. if (s > max)
  23. {
  24. max = s;
  25. max_i = i - s + 1;
  26. }
  27. }
  28. }
  29. s = 0;
  30.  
  31. }
  32. else {
  33. s++;
  34. }
  35. }
  36. if (max > 0) {
  37. for (int i = max_i; i < max + max_i; i++) {
  38. cout << line[i];
  39. }
  40. }
  41. else {
  42. cout << "Палиндромов нет" << endl;
  43. }
  44. system("pause");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement