Advertisement
a53

CountWords

a53
Nov 11th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int main()
  5. {
  6. char a[10001],cuv[100001][101],*p,separator[]=" .,;:!?\"'-*(){}[]&=_+/";
  7. cin.get(a,10001);
  8. p=a;
  9. p=strtok(p,separator);
  10. int nr=0;
  11. while(p)
  12. strcpy(cuv[++nr],p),p=strtok(NULL,separator);
  13. for(int i=1;i<nr;++i)
  14. for(int j=i+1;j<=nr;++j)
  15. if(strcmp(cuv[i],cuv[j])>0)
  16. swap(cuv[i],cuv[j]);
  17. int i=1;
  18. while(i<=nr)
  19. {
  20. int frecv=1;
  21. cout<<cuv[i];
  22. while(i+frecv<=nr&&strcmp(cuv[i],cuv[i+frecv])==0)
  23. ++frecv;
  24. cout<<' '<<frecv<<'\n';
  25. i+=frecv;
  26. }
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement