Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main() {
- string row, word, first;
- size_t size;
- bool sizeTheSame;
- bool isAnagram;
- ifstream file("anagram.txt");
- ofstream anagram("wynikiB.txt");
- ofstream sizes("wynikiA.txt");
- while (file >> first) {
- row += first;
- size = first.size();
- isAnagram = true;
- sizeTheSame = true;
- for (size_t i = 0; i < 4; ++i) {
- file >> word;
- row += ' ' + word;
- if (sizeTheSame || isAnagram) {
- if (word.size() != size) {
- sizeTheSame = false;
- }
- if (!is_permutation(first.begin(), first.end(), word.begin(), word.end())) {
- isAnagram = false;
- }
- }
- word.clear();
- }
- if (isAnagram) {
- anagram << row << "\n";
- }
- if (sizeTheSame) {
- sizes << row << "\n";
- }
- row.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement