fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int point = 5;
  11.  
  12. static int scoreBorder = 45;
  13.  
  14. static List<String> lines = new ArrayList<String>();
  15. static String linesHeader = "";
  16. static Participants participants = new Participants();
  17. static String linesBorder = "";
  18. static String linesFooter = "";
  19.  
  20.  
  21.  
  22.  
  23. public static void main (String[] args)
  24. {
  25. input();
  26. divedeLines(lines);
  27. Collections.sort(participants);
  28. System.out.println(participants);
  29. }
  30.  
  31.  
  32. static void input() {
  33. try {
  34. for ( ; ; ) {
  35. String line = reader.readLine();
  36. if (line == null) {
  37. break;
  38. }
  39. lines.add(line);
  40. }
  41. } catch (IOException e){
  42. System.out.println(e);
  43. System.exit(1);
  44. }
  45. }
  46.  
  47.  
  48.  
  49. static void divedeLines(List<String> lines) {
  50. String line = "";
  51. Iterator<String> itr = lines.iterator();
  52. for ( ; itr.hasNext(); ) {
  53. line = itr.next();
  54. if (Character.isDigit(line.charAt(0))) {
  55. break;
  56. }
  57. linesHeader += line + "\n";
  58. }
  59.  
  60. Participant participant = new Participant(line);
  61. if (participant.participates == 1) {
  62. participant.update();
  63. participants.add(participant);
  64. }
  65. for ( ; itr.hasNext(); ) {
  66. line = itr.next();
  67. if (!Character.isDigit(line.charAt(0))) {
  68. break;
  69. }
  70. participant = new Participant(line);
  71. if (participant.participates == 1) {
  72. participant.update();
  73. participants.add(participant);
  74. }
  75. }
  76. linesBorder = line;
  77. for ( ; itr.hasNext(); ) {
  78. line = itr.next();
  79. if (!Character.isDigit(line.charAt(0))) {
  80. break;
  81. }
  82. participant = new Participant(line);
  83. if (participant.participates == 1) {
  84. participant.update();
  85. participants.add(participant);
  86. }
  87. }
  88. linesFooter += line + "\n";
  89. for ( ; itr.hasNext(); ) {
  90. line = itr.next();
  91. if (Character.isDigit(line.charAt(0))) {
  92. break;
  93. }
  94. linesFooter += line + "\n";
  95. }
  96.  
  97. participants.set();
  98. }
  99.  
  100.  
  101. void output() {
  102. System.out.println(linesHeader);
  103. Iterator<Participant> itr = participants.iterator();
  104. for ( ; itr.hasNext(); ) {
  105. Participant participant = itr.next();
  106. if (participant.score <= 45.) {
  107. break;
  108. }
  109. }
  110. System.out.println(linesBorder);
  111. for ( ; itr.hasNext(); ) {
  112. Participant participant = itr.next();
  113. if (participant.score <= 45.) {
  114. break;
  115. }
  116. }
  117. System.out.println();
  118. }
  119. }
  120.  
  121.  
  122. class Participants extends ArrayList<Participant> {
  123.  
  124. double average;
  125. double sd;
  126.  
  127. void set() {
  128. setAverage();
  129. System.out.println("av= " + average);
  130. setSD();
  131. System.out.println("sd= " + sd);
  132. update();
  133. }
  134.  
  135. void setAverage() {
  136. double sum = 0.;
  137. for (Participant participant : this) {
  138. sum += participant.score;
  139. }
  140. average = sum / size();
  141. }
  142.  
  143.  
  144. void setSD() {
  145. double sum = 0.;
  146. for (Participant participant : this) {
  147. sum += (participant.score - average)
  148. * (participant.score - average);
  149. }
  150. sd = Math.sqrt(sum / (size() - 1));
  151. }
  152.  
  153.  
  154. void update() {
  155. for (Participant participant : this) {
  156. participant.score = 50. + 10. * (participant.score - average) / sd;
  157. if (participant.score < 45) {
  158. participant.score = 45;
  159. }
  160. }
  161. }
  162.  
  163.  
  164. public String toString() {
  165. String str = Ideone.linesHeader;
  166. int no = 1;
  167. int noPrev = 1;
  168. double scorePrev = 0;
  169. boolean linesBorderIsDone = false;
  170. for (Participant participant : this) {
  171. if (participant.score <= Ideone.scoreBorder) {
  172. if (! linesBorderIsDone) {
  173. str += Ideone.linesBorder + "\n";
  174. linesBorderIsDone = true;
  175. }
  176. participant.score = Ideone.scoreBorder;
  177. }
  178. if (participant.score == scorePrev) {
  179. participant.no = noPrev;
  180. } else {
  181. scorePrev = participant.score;
  182. participant.no = no;
  183. noPrev = no;
  184. }
  185. str += participant + "\n";
  186. no++;
  187. }
  188. str += Ideone.linesFooter;
  189. return str;
  190. }
  191.  
  192. }
  193.  
  194.  
  195. class Participant implements Comparable<Participant> {
  196. int no;
  197. String name;
  198. double score;
  199. int participates;
  200. String bar;
  201.  
  202. Participant(String line) {
  203. String[] words = line.split(",");
  204. try {
  205. no = Integer.parseInt(words[0]);
  206. } catch (Exception e) {
  207. System.out.println(e); // java.lang.NumberFormatException: For input string: "A"
  208. }
  209. no = Integer.parseInt(words[0]);
  210. name = words[1];
  211. score = Integer.parseInt(words[2]);
  212. participates = Integer.parseInt(words[3].trim());
  213. bar = words.length == 5 ? words[4].trim() : "";
  214. }
  215.  
  216.  
  217. void update() {
  218. if (bar != "") {
  219. score += 5 * bar.length();
  220. bar = "";
  221. }
  222. participates = 0;
  223. }
  224.  
  225.  
  226. public String toString() {
  227. return no +"," + name +"," + (int)(score+ 0.5) + ", " + participates + ",";
  228. }
  229.  
  230.  
  231. public int compareTo(Participant a) {
  232. if (score > a.score) {
  233. return -1;
  234. } else if (score < a.score) {
  235. return +1;
  236. } else {
  237. return name.compareTo(a.name);
  238. }
  239. }
  240. }
Success #stdin #stdout 0.23s 60784KB
stdin
,,,,
,,,,単語クイズ 英語 2023年9~10月
,,,,
順,   ,持,参,
位,名前 ,点,加,優勝回
1,のりI,57, 1,2
11,しんI,50,1,
,,,,-------------------------以下、辞書順
2,みちS,45, 1,134
,,,,
,,,,持点とは前期の成績から求めた偏差値。
,,,,ただし、45点未満は45点とする。
,,,,毎回、最高得点者に5点加点。
,,,,最高得点者のうち下位者をその回の優勝者とする。
,,,,優勝者はその後の活動のリクエストをすることができる。
,,,,
,,,,更新 1/31
stdout
av= 57.333333333333336
sd= 6.429100507328637
,,,,
,,,,単語クイズ 英語 2023年9~10月
,,,,
順,   ,持,参,
位,名前 ,点,加,優勝回
1,のりI,57, 0,
2,みちS,54, 0,
,,,,-------------------------以下、辞書順
3,しんI,45, 0,
,,,,
,,,,持点とは前期の成績から求めた偏差値。
,,,,ただし、45点未満は45点とする。
,,,,毎回、最高得点者に5点加点。
,,,,最高得点者のうち下位者をその回の優勝者とする。
,,,,優勝者はその後の活動のリクエストをすることができる。
,,,,
,,,,更新 1/31