Advertisement
Niloy007

SolutionE

Feb 24th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct node {
  5.     int data;
  6.     char ch;
  7.     struct node *next;
  8. };
  9. typedef struct node Node;
  10.  
  11. Node *head = new Node();
  12.  
  13. void createNode(Node *head) {
  14.     Node *temp, *last, *flag;
  15.  
  16.     last = head;
  17.     int i = 0;
  18.     while (i < 26) {
  19.         temp = new Node();
  20.         temp->ch = (char) (97 + i);
  21.         temp->data = 0;
  22.         temp->next = NULL;
  23.         last->next = temp;
  24.         last = last->next;
  25.         i++;
  26.     }
  27.  
  28. }
  29.  
  30.  
  31. string beforeCheck(string msg) {
  32.     for(int i = 0; i < msg.size(); i++) {
  33.         if(msg.at(i) >= 'A' && msg.at(i) <= 'Z') {
  34.             msg.at(i) += 32;
  35.         }
  36.     }
  37.     return msg;
  38. }
  39.  
  40.  
  41.  
  42. Node *check(Node *head, string msg) {
  43.     Node *temp;
  44.     temp = head->next;
  45.     int i = 0;
  46.  
  47.     while (i < msg.size()) {
  48.         temp = head->next;
  49.         while(temp != NULL) {
  50.             if (msg.at(i) == temp->ch) {
  51.                 temp->data++;
  52.                 i++;
  53.                 break;
  54.             }
  55.             temp = temp->next;
  56.         }
  57.     }
  58.     return head;
  59. }
  60.  
  61.  
  62. void display(Node *head) {
  63.     Node *temp;
  64.     temp = head;
  65.  
  66.     while (temp->next != NULL) {
  67.         cout << temp->next->ch << ": " << temp->next->data << "\n";
  68.         temp = temp->next;
  69.     }
  70. }
  71.  
  72.  
  73. int main() {
  74.     createNode(head);
  75.     string msg;
  76.     cin >> msg;
  77.     msg = beforeCheck(msg);
  78.     head = check(head, msg);
  79.     display(head);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement