Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <vector>
- #include <map>
- #include <cmath>
- int main()
- {
- // Typy ifstream oraz ofstream nie potrzebuja zamykania
- // Recznego, poniewaz maja wlasny destruktor
- // Przy skonczeniu programu
- std::ifstream input("sygnaly.txt");
- std::ofstream output("wyniki4.txt");
- std::vector<std::string> dane;
- std::string temp;
- while (input >> temp)
- {
- dane.emplace_back(temp);
- }
- // Zadanie 4.1
- std::string przeslanie;
- for (int i = 39; i < dane.size(); i += 40)
- przeslanie += dane[i][9];
- output << "Zadanie 4.1:\n" << przeslanie << std::endl;
- // Zadanie 4.2
- std::vector<std::map<char, int>> liczniki;
- for (int i = 0; i < dane.size(); i++)
- {
- // Dodanie pustej mapy do licznika
- liczniki.emplace_back();
- for (int j = 0; j < dane[i].size(); j++)
- {
- // Najpierw odwolanie do licznika tablicy - licznik[i]
- // Potem odwolanie do danego napisu - dane[i]
- // A nastepnie do kazdej litery - dane[i][j]
- liczniki[i][dane[i][j]]++;
- }
- }
- // Szukanie wartosci maksymalnej
- int max = 0;
- int index = -1;
- for (int i = 0; i < liczniki.size(); i++)
- {
- if (liczniki[i].size() > max)
- {
- max = liczniki[i].size();
- index = i;
- }
- }
- output << "Zadanie 4.2:\n" << dane[index] << " oraz liczba roznych znakow: " << max << std::endl;
- // Zadanie 4.3
- output << "Zadanie 4.3:\n";
- for (auto& wyraz : dane)
- {
- bool czySpelniaWarunek = true;
- for (auto &litera1 : wyraz)
- {
- for (auto &litera2 : wyraz)
- {
- if (abs(litera1 - litera2) > 10)
- {
- czySpelniaWarunek = false;
- break;
- }
- }
- if (!czySpelniaWarunek)
- {
- break;
- }
- }
- if (czySpelniaWarunek) output << wyraz << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement