Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- std::string SortowanieBabelkowe(std::string s) {
- for (int i = 0; i < s.size(); i++) {
- for (int j = i; j < s.size(); j++) {
- if (s[j] < s[i])
- std::swap(s[j], s[i]);
- }
- }
- return s;
- }
- std::string StringToLower(std::string text) {
- for (int i = 0; i < text.size(); i++) {
- text[i] = tolower(text[i]);
- }
- return text;
- }
- bool CzyAnagram(std::string a, std::string b) {
- if (a.size() == b.size())
- return SortowanieBabelkowe(StringToLower(a)) == SortowanieBabelkowe(StringToLower(b));
- return false;
- }
- bool CzyJednolity(std::string text){
- if (text.size() > 0) {
- char litera = text[0];
- for (int i = 1; i < text.size(); i++) {
- if (litera != text[i])
- return false;
- }
- }
- return true;
- }
- bool CzyJednolityAnagram(std::string a, std::string b) {
- if (a.size() > 0 && b.size() > 0) {
- if (CzyJednolity(a) && CzyJednolity(b)) {
- return (a.size() == b.size()) && (a[0] == b[0]);
- }
- return false;
- }
- return true;
- }
- int main()
- {
- std::ifstream plik;
- plik.open("dane_napisy.txt");
- int zad1 = 0, zad2 = 0;
- while (plik) {
- std::string a, b;
- plik >> a >> b;
- if (a != "" && b != "") {
- if (CzyJednolityAnagram(a, b))
- zad1++;
- if (CzyAnagram(a, b))
- zad2++;
- }
- }
- std::cout << zad1 << " " << zad2 << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment