Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- using namespace std;
- string readInput()
- {
- string input;
- getline(cin, input);
- return input;
- }
- vector<string> makeSentences(string& text)
- {
- vector<string> result;
- string sentence;
- int size = text.size();
- for (int i = 0; i < size; i++)
- {
- if (text[i] == '|')
- {
- result.push_back(sentence);
- text.erase(i, 1);
- size -= 1;
- sentence = "";
- }
- sentence.push_back(text[i]);
- }
- return result;
- }
- void printOutput(const map<int, int> &out)
- {
- for (pair<int ,int> element : out)
- {
- cout << element.first << " symbol sentences: " << element.second << endl;
- }
- }
- int main()
- {
- string inputText = readInput();
- vector<string> sentences = makeSentences(inputText);
- map<int, int> output;
- for (string element : sentences)
- {
- const int size = element.size();
- int symbols = 0;
- for (int i = 0; i < size; i++)
- {
- if (ispunct(element[i]))
- {
- ++symbols;
- }
- }
- output[symbols]++;
- }
- printOutput(output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment