mitakvd

1. Punctuation

Nov 24th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. string readInput()
  9. {
  10.     string input;
  11.     getline(cin, input);
  12.     return input;
  13. }
  14.  
  15. vector<string> makeSentences(string& text)
  16. {
  17.     vector<string> result;
  18.     string sentence;
  19.     int size = text.size();
  20.     for (int i = 0; i < size; i++)
  21.     {
  22.         if (text[i] == '|')
  23.         {
  24.             result.push_back(sentence);
  25.             text.erase(i, 1);
  26.             size -= 1;
  27.             sentence = "";
  28.         }
  29.         sentence.push_back(text[i]);
  30.     }
  31.     return result;
  32. }
  33.  
  34. void printOutput(const map<int, int> &out)
  35. {
  36.     for (pair<int ,int> element : out)
  37.     {
  38.         cout << element.first << " symbol sentences: " << element.second << endl;
  39.     }
  40. }
  41.  
  42. int main()
  43. {
  44.     string inputText = readInput();
  45.  
  46.     vector<string> sentences = makeSentences(inputText);
  47.  
  48.     map<int, int> output;
  49.    
  50.     for (string element : sentences)
  51.     {
  52.         const int size = element.size();
  53.         int symbols = 0;
  54.         for (int i = 0; i < size; i++)
  55.         {
  56.             if (ispunct(element[i]))
  57.             {
  58.                 ++symbols;
  59.             }
  60.         }
  61.         output[symbols]++;
  62.     }
  63.  
  64.     printOutput(output);
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment