fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct word_and_counter {
  8. string word;
  9. unsigned counter;
  10. word_and_counter(string w="", int c=1) {
  11. word = w;
  12. counter = c;
  13. }
  14. };
  15.  
  16. bool words_comparator(word_and_counter a, word_and_counter b) {
  17. return a.word < b.word;
  18. }
  19.  
  20. bool counts_comparator(word_and_counter a, word_and_counter b) {
  21. return a.counter > b.counter;
  22. }
  23.  
  24. int main() {
  25. vector<word_and_counter> x;
  26. for(string s; cin >> s; ) {
  27. auto it = std::remove_if(s.begin(), s.end(), ::ispunct);
  28. s.erase(it, s.end());
  29. transform(s.begin(), s.end(), s.begin(), ::tolower);
  30. x.push_back(s);
  31. }
  32. sort(x.begin(), x.end(), words_comparator);
  33. for(int i=1; i < x.size(); ++i)
  34. if (x[i].word == x[i-1].word) {
  35. x[i].counter += x[i-1].counter;
  36. x[i-1].counter = 0;
  37. }
  38. sort(x.begin(), x.end(), counts_comparator);
  39. for(auto e: x)
  40. if (e.counter > 0) cout << e.word << ' ' << e.counter << endl;
  41. }
Success #stdin #stdout 0.01s 5476KB
stdin
I would like to keep the app simple and only support one piece of text. It’s kinda in the app name. However, the app comes with a shortcut action to change the text, so you could use the Shortcuts automation to change the text during the day.
stdout
the 7
app 3
to 3
text 3
change 2
support 1
name 1
of 1
one 1
a 1
piece 1
shortcut 1
shortcuts 1
simple 1
so 1
only 1
use 1
with 1
would 1
you 1
kinda 1
action 1
and 1
automation 1
comes 1
could 1
day 1
however 1
like 1
keep 1
it’s 1
in 1
i 1
during 1