fork download
  1. program GradeStatistics;
  2. uses math;
  3.  
  4. const
  5. MIN_STUDENTS = 10;
  6.  
  7. type
  8. TDataArray = array of Real;
  9.  
  10. var
  11. scores: TDataArray;
  12. count, i, j, passCount: Integer;
  13. inputVal: Real;
  14. sum, mean, median, minScore, maxScore, sumSqDiff, stdDev: Real;
  15. temp: Real;
  16.  
  17. begin
  18. count := 0;
  19.  
  20. // 1. 標準入力(stdin)から点数をすべて読み込む
  21. while not SeekEof do
  22. begin
  23. read(inputVal); // 【修正】ReadLine から read に変更
  24. count := count + 1;
  25. SetLength(scores, count);
  26. scores[count - 1] := inputVal;
  27. end;
  28.  
  29. // バリデーション:10人以上いるか確認
  30. if count < MIN_STUDENTS then
  31. begin
  32. writeln('エラー: 生徒の数は10人以上にする必要があります。(現在: ', count, '人)');
  33. Exit;
  34. end;
  35.  
  36. // 2. 統計の計算(合計、最高点、最低点、合格者数)
  37. sum := 0;
  38. minScore := scores[0];
  39. maxScore := scores[0];
  40. passCount := 0;
  41.  
  42. for i := 0 to count - 1 do
  43. begin
  44. sum := sum + scores[i];
  45. if scores[i] > maxScore then maxScore := scores[i];
  46. if scores[i] < minScore then minScore := scores[i];
  47. if scores[i] >= 60.0 then passCount := passCount + 1;
  48. end;
  49.  
  50. mean := sum / count;
  51.  
  52. // 3. 中央値計算のためにソート(バブルソート)
  53. for i := 0 to count - 2 do
  54. begin
  55. for j := 0 to count - 2 - i do
  56. begin
  57. if scores[j] > scores[j + 1] then
  58. begin
  59. temp := scores[j];
  60. scores[j] := scores[j + 1];
  61. scores[j + 1] := temp;
  62. end;
  63. end;
  64. end;
  65.  
  66. // 中央値の決定
  67. if (count mod 2) = 1 then
  68. median := scores[count div 2]
  69. else
  70. median := (scores[(count div 2) - 1] + scores[count div 2]) / 2.0;
  71.  
  72. // 4. 標準偏差の計算
  73. sumSqDiff := 0;
  74. for i := 0 to count - 1 do
  75. begin
  76. sumSqDiff := sumSqDiff + sqr(scores[i] - mean);
  77. end;
  78. stdDev := sqrt(sumSqDiff / count);
  79.  
  80. // 5. 結果の出力
  81. writeln('--- 成績集計結果 ---');
  82. writeln('学生数 : ', count, ' 人');
  83. writeln('平均点 : ', mean:0:2);
  84. writeln('中央値 : ', median:0:2);
  85. writeln('最高点 : ', maxScore:0:2);
  86. writeln('最低点 : ', minScore:0:2);
  87. writeln('標準偏差 : ', stdDev:0:2);
  88. writeln('合格者数 : ', passCount, ' 人 (60点以上)');
  89. writeln;
  90.  
  91. writeln('--- 各自の偏差値 ---');
  92. for i := 0 to count - 1 do
  93. begin
  94. if stdDev > 0 then
  95. temp := 50.0 + 10.0 * (scores[i] - mean) / stdDev
  96. else
  97. temp := 50.0;
  98.  
  99. writeln('得点: ', scores[i]:6:2, ' -> 偏差値: ', temp:0:2);
  100. end;
  101. end.
Success #stdin #stdout 0s 5292KB
stdin
85 72 59 45 90 68 77 82 30 95 60 71
stdout
--- 成績集計結果 ---
学生数    : 12 人
平均点    : 69.50
中央値    : 71.50
最高点    : 95.00
最低点    : 30.00
標準偏差  : 18.02
合格者数  : 9 人 (60点以上)

--- 各自の偏差値 ---
得点:  30.00 -> 偏差値: 28.08
得点:  45.00 -> 偏差値: 36.40
得点:  59.00 -> 偏差値: 44.17
得点:  60.00 -> 偏差値: 44.73
得点:  68.00 -> 偏差値: 49.17
得点:  71.00 -> 偏差値: 50.83
得点:  72.00 -> 偏差値: 51.39
得点:  77.00 -> 偏差値: 54.16
得点:  82.00 -> 偏差値: 56.94
得点:  85.00 -> 偏差値: 58.60
得点:  90.00 -> 偏差値: 61.38
得点:  95.00 -> 偏差値: 64.15