Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <limits.h>
  4. #include <vector>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. struct list {
  12. char cur;
  13. int count = 0;
  14. list* next;
  15. };
  16.  
  17. int main () {
  18. string s;
  19. getline(cin,s);
  20. list *p;
  21. p=new list;
  22. p->cur = s[0];
  23. p->count = 1;
  24. p->next = NULL;
  25. unsigned long len = s.length();
  26. list *q = p;
  27. for (int i = 1; i < len; i++) {
  28. int pr = 0;
  29. while (q->next != NULL) {
  30. if (q->cur == s[i]) {
  31. pr++;
  32. q->count++;
  33. }
  34. q = q->next;
  35. }
  36. if (pr == 0) {
  37. q->next = new list;
  38. q = q->next;
  39. q->cur = s[i];
  40. q->count = 1;
  41. q->next= NULL;
  42. }
  43. q = p;
  44.  
  45.  
  46. }
  47. while (q != NULL)
  48. {
  49. cout << q->cur << " " << q->count << " ";
  50. q = q->next;
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement