Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- bool areAnagrams(string a, string b)
- {
- int lengthA = a.length();
- int lengthB = b.length();
- int j = 0;
- if(lengthA != lengthB)
- return false;
- sort(a.begin(),a.end());
- sort(b.begin(),b.end());
- for(int j = 0; j < lengthA; j++)
- if(a[j] != b[j])
- return false;
- return true;
- }
- bool subcheck(string check, string a)
- {
- int checkCount = 0;
- for(int i = 0; i < a.length() - 2; i++)
- {
- if(a.substr(i,3) == check)
- checkCount++;
- }
- if(checkCount > 1)
- return true;
- }
- int main()
- {
- ifstream data("hasla.txt");
- ofstream result;
- result.open("wynik.txt", ios::out);
- vector<string> result42 ;
- string a, b;
- string combos[6] = {"CBA","CAB","BAC","BCA","ACB","ABC"};
- int i = 0, anagramCount = 0, checkTrueA = 0, checkTrueB = 0;
- for(i = 0; i< 1000; i++)
- {
- data >> a >> b;
- if(areAnagrams(a,b) == true)
- anagramCount ++;
- for(int j = 0; j < 6; j++)
- {
- if(subcheck(combos[j],a))
- checkTrueA ++;
- if(subcheck(combos[j],b))
- checkTrueB ++;
- }
- if(checkTrueA > 0)
- result42.push_back(a);
- if(checkTrueB > 0)
- result42.push_back(b);
- }
- cout << anagramCount;
- result << "4.1" << endl << "ilosc anagramow: " << anagramCount << endl;
- result.close();
- for(i = 0; i< result42.size(); i++)
- {
- cout << result42[i]<< endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement