Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <Windows.h>
- #include <string>
- using namespace std;
- pair<string*, size_t*> addNewWord(string* words, size_t* repeats, size_t& size, const string& newWord)
- {
- string* newWords = new string[size + 1];
- size_t* newRepeats = new size_t[size + 1];
- for (size_t i = 0; i < size; i++)
- {
- newWords[i] = words[i];
- newRepeats[i] = repeats[i];
- }
- newWords[size] = newWord;
- newRepeats[size] = 1;
- size++;
- return pair<string*, size_t*>(newWords, newRepeats);
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- ifstream input("input.txt");
- if (!input.is_open())
- {
- cout << "File not found";
- return 0;
- }
- string* words = nullptr;
- size_t* repeats = nullptr;
- size_t amount = 0;
- while (input.good())
- {
- string tmp;
- getline(input, tmp);
- const pair<string*, size_t*> response = addNewWord(words, repeats, amount, tmp);
- words = response.first;
- repeats = response.second;
- }
- input.close();
- for (int i = 0; i < amount - 1; i++) {
- for (int j = 0; j < amount - i - 1; j++) {
- if (repeats[j] > repeats[j + 1]) {
- swap(words[j], words[i]);
- swap(repeats[j], repeats[i]);
- }
- }
- }
- for(size_t i =0 ; i < amount; i++)
- {
- cout << words[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement