Guest User

Untitled

a guest
Oct 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. // 回答開始
  11. int n;
  12. cin >> n;
  13. int x[n];
  14.  
  15. // 平均値
  16. double mean = 0.0;
  17. for (int i = 0; i < n; i++) {
  18. cin >> x[i];
  19. mean += x[i];
  20. }
  21.  
  22. mean /= n;
  23. cout << mean << endl;
  24.  
  25. // メジアン(中央値)
  26. sort(x, x + n);
  27. if (n % 2 == 1) {
  28. cout << x[(n + 1) / 2 - 1] << endl;
  29. } else {
  30. cout << (x[n / 2 - 1] + x[n / 2 + 1 - 1]) / 2.0 << endl;
  31. }
  32.  
  33. // モード(最頻値)
  34. int counter[100000] = {0};
  35. int max_n = x[0];
  36. for (int i = 0; i < n; i++) {
  37. counter[x[i]]++;
  38. }
  39.  
  40. for (int i = x[0]; i < n; i++) {
  41. if (counter[i] == 0)
  42. continue;
  43. if (counter[i] > counter[max_n])
  44. max_n = i;
  45. }
  46. cout << max_n << endl;
  47. // 回答終了
  48.  
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment