Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <queue>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. #ifdef _DEBUG
  13. freopen("input.txt","r",stdin);
  14. freopen("output.txt","w",stdout);
  15. #endif
  16. string str = "abcdefghijklmnopqrstuvwxwzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  17. vector <string> a;
  18. map <unsigned char, float> m;
  19. while (cin)
  20. {
  21. string s;
  22. getline(cin, s);
  23. if (s != "")
  24. {
  25. a.push_back(s);
  26. }
  27. }
  28. for (int i = 0; i < a.size(); ++i)
  29. {
  30. for (int j = 0; j < a[i].length(); ++j)
  31. {
  32. if (isalpha(a[i][j]))
  33. {
  34. if (m.find(a[i][j]) == m.end())
  35. m.insert(make_pair(a[i][j], 1));
  36. else
  37. m.find(a[i][j])->second++;
  38. }
  39. }
  40. }
  41. for (auto it = m.begin(); it != m.end(); ++it)
  42. {
  43. for (int i = 0; i < str.length(); ++i)
  44. {
  45. if (m.find(str[i]) == m.end())
  46. m.insert(make_pair(str[i], 0));
  47. }
  48. }
  49. int n = 0;
  50. for (int i = 0; i < a.size(); ++i)
  51. n += a[i].length();
  52. for (auto it = m.begin(); it != m.end(); ++it)
  53. {
  54. cout << it->first << ": ";
  55. printf("%.3f",it->second/n);
  56. cout << endl;
  57. }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement