Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <limits.h>
- #include <vector>
- #include <string>
- #include <set>
- #include <map>
- using namespace std;
- struct list {
- char cur;
- int count = 0;
- list* next;
- };
- int main () {
- string s;
- getline(cin,s);
- list *p;
- p=new list;
- p->cur = s[0];
- p->count = 1;
- p->next = NULL;
- unsigned long len = s.length();
- list *q = p;
- for (int i = 1; i < len; i++) {
- int pr = 0;
- while (q->next != NULL) {
- if (q->cur == s[i]) {
- pr++;
- q->count++;
- }
- q = q->next;
- }
- if (pr == 0) {
- q->next = new list;
- q = q->next;
- q->cur = s[i];
- q->count = 1;
- q->next= NULL;
- }
- q = p;
- }
- while (q != NULL)
- {
- cout << q->cur << " " << q->count << " ";
- q = q->next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement