Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <stdlib.h>
- #include <string>
- #include <algorithm>
- using namespace std;
- bool ispalind(const string& s)
- {
- return s == string(s.rbegin(), s.rend());
- }
- /*bool ispalind(string s)
- {
- string s2 = s;
- size_t i;
- while ((i = s.find(' ')) != string::npos)
- s.erase(i, 1);
- string rs = s;
- reverse(rs.begin(), rs.end());
- return s == rs;
- }*/
- int main()
- {
- setlocale(LC_ALL, "Russian")
- ifstream input("in.txt");
- if (!input.is_open())
- cout << "Файл не может быть открыт!\n";
- else
- {
- ofstream output("out.txt");
- if (!output.is_open())
- {
- cout << "Файл не может быть открыт или создан\n";
- return 1;
- }
- ofstream output_without_palindrom("no_palindrom_string.txt");
- if (!output_without_palindrom.is_open())
- {
- cout << "Файл не может быть открыт или создан\n";
- return 1;
- }
- string s;
- while (getline(input, s))
- if (ispalind(s)) output << s << endl;
- else output_without_palindrom << s << endl;
- input.close();
- output_without_palindrom.close();
- output.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement