fork(1) 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] year ={2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026};
  13. int[] at_bat ={3,286,142,302,527,569,554,557,394,527,532,533,477,333,305,409,372,387,239,157,124,23,13};
  14. int[] hits ={1,85,38,84,167,152,172,171,114,147,153,143,133,84,78,103,101,97,63,34,28,2,2};
  15. int[] games ={1,84,63,112,138,140,144,144,103,144,144,142,135,116,114,123,111,117,89,77,60,11,11};
  16. double[] anda = new double[games.length];
  17. for(int i=0;i<games.length;i++){ //ソート開始
  18. for(int j = i+1;j<games.length;j++){ //i+1~最後までを比較
  19. if(games[i]<games[j]){
  20. int a = year[i];
  21. year[i] = year[j];
  22. year[j] = a;
  23. int b = at_bat[i];
  24. at_bat[i] = at_bat[j];
  25. at_bat[j] = b;
  26. int c = hits[i];
  27. hits[i] = hits[j];
  28. hits[j] = c;
  29. int d = games[i];
  30. games[i] =games[j];
  31. games[j] = d; //比較したとき大きいとき値を代入
  32. }
  33. }
  34. }
  35. for(int i=0;i<hits.length;i++){ //打率の計算
  36. anda[i] = (double) hits[i]/at_bat[i];
  37. }
  38. for(int i=0;i<year.length;i++){
  39. System.out.printf(year[i]+ " ");
  40. System.out.printf(games[i]+ " ");
  41. System.out.printf(at_bat[i]+ " ");
  42. System.out.printf(hits[i]+ " ");
  43. System.out.printf("%.3f",anda[i]);
  44. System.out.printf("\n");
  45. }
  46.  
  47. System.out.printf("\n");
  48. int allg=0;
  49. int allab=0;
  50. int allh=0;
  51. double allad=0;
  52. for(int i=0;i<games.length;i++){ //初期値0に配列の値を追加していく
  53. allg = allg+games[i];
  54. allab = allab+at_bat[i];
  55. allh = allh+hits[i];
  56. allad = (double) allh/allab;
  57. }
  58. System.out.printf("%d\n",allg);
  59. System.out.printf("%d\n",allab);
  60. System.out.printf("%d\n",allh);
  61. System.out.printf("%f\n",allad);
  62. }
  63.  
  64. }
Success #stdin #stdout 0.15s 56512KB
stdin
Standard input is empty
stdout
2010 144 554 172 0.310
2011 144 557 171 0.307
2013 144 527 147 0.279
2014 144 532 153 0.288
2015 142 533 143 0.268
2009 140 569 152 0.267
2008 138 527 167 0.317
2016 135 477 133 0.279
2019 123 409 103 0.252
2021 117 387 97 0.251
2017 116 333 84 0.252
2018 114 305 78 0.256
2007 112 302 84 0.278
2020 111 372 101 0.272
2012 103 394 114 0.289
2022 89 239 63 0.264
2005 84 286 85 0.297
2023 77 157 34 0.217
2006 63 142 38 0.268
2024 60 124 28 0.226
2025 11 23 2 0.087
2026 11 13 2 0.154
2004 1 3 1 0.333

2323
7765
2152
0.277141