Advertisement
Spocoman

03. Punctuation

Nov 23rd, 2023 (edited)
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string line;
  9.     getline(cin, line);
  10.  
  11.     map<int, int> results;
  12.  
  13.     while (line.length() != 0) {
  14.         size_t punct = 0, index = line.find('|');
  15.         for (size_t i = 0; i < line.substr(0, index).length(); i++) {
  16.             if (ispunct(line[i])) {
  17.                 punct++;
  18.             }
  19.         }
  20.         line.erase(0, index + 1);
  21.         results[punct]++;
  22.     }
  23.  
  24.     for (map<int, int>::iterator it = results.begin(); it != results.end(); it++) {
  25.         cout << it->first << " symbol sentences: " << it->second << endl;
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement