nsnikolova1

Message

May 18th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. // Messge Count word to repead.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <sstream>
  7. #include <map>
  8. #include <vector>
  9. #include <algorithm>
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     string input, word;
  16.     int occurrenceCount, index, N, count;
  17.    map<string, int>Centence;
  18.     vector<pair<int, int>>Ocurence;
  19.     vector<string>Result;
  20.  
  21.     while (word != ".")
  22.     {
  23.         cin >> word;
  24.         Centence[word]++;
  25.     }
  26.  
  27.     cin >> N; //number of queri
  28.     for (int i = 0; i < N; i++)
  29.     {
  30.         cin >> occurrenceCount >> index;
  31.         Ocurence.push_back(make_pair(occurrenceCount, index));
  32.     }
  33.  
  34.     for (auto it = Ocurence.begin(); it != Ocurence.end(); it++)
  35.     {
  36.         for (auto itC = Centence.begin(); itC != Centence.end(); itC++)
  37.         {
  38.             if ((it->first) == (itC->second))
  39.             {
  40.                 Result.push_back(itC->first);
  41.             }
  42.         }
  43.  
  44.         //vtora proverka po index
  45.    //    sort(Result.begin(), Result.end());
  46.         if (Result.empty())
  47.         {
  48.             cout << "." << endl;
  49.             break;
  50.         }
  51.         else if ((it->second) > Result.size())
  52.         {
  53.             break;
  54.         }
  55.         for (int k = 0; k < Result.size(); k++)
  56.         {
  57.            
  58.             if ((it->second) == k)
  59.             {
  60.                 cout << Result[k] << endl;
  61.                 break;
  62.             }
  63.         }
  64.  
  65.         Result.clear();
  66.     }
  67.  
  68.  
  69.  
  70. }
  71.  
  72. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  73. // Debug program: F5 or Debug > Start Debugging menu
  74.  
  75. // Tips for Getting Started:
  76. //   1. Use the Solution Explorer window to add/manage files
  77. //   2. Use the Team Explorer window to connect to source control
  78. //   3. Use the Output window to see build output and other messages
  79. //   4. Use the Error List window to view errors
  80. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  81. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment