fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <set>
  5.  
  6. // Заполняем вектор частот символов
  7. // Сохраняем все символы алфавита в std::set
  8. void get_data(std::vector< std::pair<char, double> > &alpha){
  9. std::vector<char> fr(256);
  10. char c;
  11. double freq;
  12.  
  13. while(std::cin >> c){
  14. fr[c]++; // Вектор хранит количество символов с кодом c
  15. // Добавить новую пару в том случае, если символа c нет в векторе
  16. alpha.push_back(std::make_pair(c, -1));
  17. }
  18. for(auto it = alpha.begin(); it != alpha.end(); it++)
  19. (*it).second = 1.0 * fr[(*it).first] / alpha.size();
  20. }
  21.  
  22. void Huffman(std::set<char> &alpha, std::vector<double> &freq){
  23.  
  24. }
  25.  
  26. int main(){
  27. std::vector< std::pair<char, double> > alpha;
  28.  
  29. get_data(alpha);
  30.  
  31. for(auto it = alpha.begin(); it != alpha.end(); it++){
  32. std::cout << (*it).first;
  33. std::cout << " ";
  34. std::cout << (*it).second;
  35. std::cout << std::endl;
  36. }
  37. }
Success #stdin #stdout 0s 3464KB
stdin
sgsdhdfhdnd
stdout
s 0.333333
g 0.166667
d 0.666667
h 0.333333
f 0.166667
n 0.166667