Advertisement
Jannec22

Matura2010-Anagramy

Mar 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11.     string row, word, first;
  12.     size_t size;
  13.     bool sizeTheSame;
  14.     bool isAnagram;
  15.     ifstream file("anagram.txt");
  16.     ofstream anagram("wynikiB.txt");
  17.     ofstream sizes("wynikiA.txt");
  18.  
  19.     while (file >> first) {
  20.  
  21.         row += first;
  22.         size = first.size();
  23.         isAnagram = true;
  24.         sizeTheSame = true;
  25.  
  26.         for (size_t i = 0; i < 4; ++i) {
  27.  
  28.             file >> word;
  29.             row += ' ' + word;
  30.  
  31.             if (sizeTheSame || isAnagram) {
  32.  
  33.                 if (word.size() != size) {
  34.                     sizeTheSame = false;
  35.                 }
  36.  
  37.                 if (!is_permutation(first.begin(), first.end(), word.begin(), word.end())) {
  38.                     isAnagram = false;
  39.                 }
  40.             }
  41.  
  42.             word.clear();
  43.  
  44.         }
  45.  
  46.         if (isAnagram) {
  47.             anagram << row << "\n";
  48.         }
  49.  
  50.         if (sizeTheSame) {
  51.             sizes << row << "\n";
  52.         }
  53.  
  54.         row.clear();
  55.  
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement