Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #define SIZE 30
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. void printCharWithFreq(string str)
  8. {
  9. int n = str.size();
  10.  
  11. int freq[SIZE];
  12.  
  13. memset(freq, 0, sizeof(freq));
  14.  
  15. for (int i = 0; i < n; i++)
  16. freq[str[i] - 'a']++;
  17.  
  18. for (int i = 0; i < n; i++)
  19. {
  20. if (freq[str[i] - 'a'] != 0)
  21. {
  22.  
  23. cout << str[i] << freq[str[i] - 'a'] << " ";
  24. }
  25. freq[str[i] - 'a'] = 0;
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. string str = "venividivici";
  32. printCharWithFreq(str);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement