fork download
  1. #include<bits/stdc++.h>
  2. #define endl '\n'
  3. using namespace std;
  4.  
  5. set < string > s;
  6. set < string > :: iterator it;
  7. multiset < string > ms;
  8.  
  9. int main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. string str;
  13. cin >> str;
  14. while (cin >> str) {
  15. s.insert(str);
  16. ms.insert(str);
  17. }
  18. cout << s.size() << endl;
  19. for (it = s.begin() ; it != s.end(); it++) {
  20. cout << *it << " " << ms.count(*it) << endl;
  21. }
  22. }
Success #stdin #stdout 0s 15240KB
stdin
AF AE AB AC AD
AB AC AD AE AF
stdout
5
AB 2
AC 2
AD 2
AE 2
AF 1