Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <stdlib.h>
  6. #include <string>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. bool ispalind(const string& s)
  11. {
  12. return s == string(s.rbegin(), s.rend());
  13. }
  14. /*bool ispalind(string s)
  15. {
  16. string s2 = s;
  17. size_t i;
  18.  
  19. while ((i = s.find(' ')) != string::npos)
  20. s.erase(i, 1);
  21.  
  22. string rs = s;
  23. reverse(rs.begin(), rs.end());
  24. return s == rs;
  25.  
  26. }*/
  27.  
  28. int main()
  29. {
  30. setlocale(LC_ALL, "Russian")
  31. ifstream input("in.txt");
  32. if (!input.is_open())
  33. cout << "Файл не может быть открыт!\n";
  34. else
  35. {
  36. ofstream output("out.txt");
  37.  
  38. if (!output.is_open())
  39. {
  40. cout << "Файл не может быть открыт или создан\n";
  41. return 1;
  42. }
  43.  
  44. ofstream output_without_palindrom("no_palindrom_string.txt");
  45.  
  46. if (!output_without_palindrom.is_open())
  47. {
  48. cout << "Файл не может быть открыт или создан\n";
  49. return 1;
  50. }
  51.  
  52. string s;
  53. while (getline(input, s))
  54.  
  55. if (ispalind(s)) output << s << endl;
  56. else output_without_palindrom << s << endl;
  57. input.close();
  58. output_without_palindrom.close();
  59. output.close();
  60. }
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement