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[] games ={2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024};
  13. int[] at_bat ={36,210,527,547,407,531,539,569,472,540,450,440,226,338,263,212};
  14. int[] hits ={10,49,125,131,124,143,142,142,102,143,109,105,40,91,67,46};
  15. int[] HomeRuns ={0,9,18,24,28,27,30,25,16,25,24,31,7,24,15,4};
  16. double[] anda = new double[games.length];
  17. for(int i=0;i<at_bat.length;i++){ //ソート開始
  18. for(int j = i+1;j<at_bat.length;j++){ //i+1~最後までを比較
  19. if(at_bat[i]<at_bat[j]){
  20. int a = games[i];
  21. games[i] = games[j];
  22. games[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 = HomeRuns[i];
  30. HomeRuns[i] =HomeRuns[j];
  31. HomeRuns[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<games.length;i++){
  39. System.out.printf(games[i]+ " ");
  40. }
  41. System.out.printf("\n");
  42. for(int i=0;i<at_bat.length;i++){
  43. System.out.printf(at_bat[i]+ " ");
  44. }
  45. System.out.printf("\n");
  46. for(int i=0;i<hits.length;i++){
  47. System.out.printf(hits[i]+ " ");
  48. }
  49. System.out.printf("\n");
  50. for(int i=0;i<HomeRuns.length;i++){
  51. System.out.printf(HomeRuns[i]+ " ");
  52. }
  53. System.out.printf("\n");
  54. for(int i=0;i<anda.length;i++){
  55. System.out.printf(anda[i]+ " ");
  56. }
  57. System.out.printf("\n");
  58. int alla=0;
  59. int allh=0;
  60. int allhr=0;
  61. double allad=0;
  62. for(int i=0;i<at_bat.length;i++){ //初期値0に配列の値を追加していく
  63. alla = alla+at_bat[i];
  64. allh = allh+hits[i];
  65. allhr = allhr+HomeRuns[i];
  66. allad = (double) allh/alla;
  67. }
  68. System.out.printf("%d\n",alla);
  69. System.out.printf("%d\n",allh);
  70. System.out.printf("%d\n",allhr);
  71. System.out.printf("%f\n",allad);
  72. }
  73.  
  74. }
Success #stdin #stdout 0.13s 58432KB
stdin
Standard input is empty
stdout
2016 2012 2018 2015 2014 2011 2017 2019 2020 2013 2022 2023 2021 2024 2010 2009 
569 547 540 539 531 527 472 450 440 407 338 263 226 212 210 36 
142 131 143 142 143 125 102 109 105 124 91 67 40 46 49 10 
25 24 25 30 27 18 16 24 31 28 24 15 7 4 9 0 
0.24956063268892795 0.23948811700182815 0.26481481481481484 0.2634508348794063 0.2693032015065913 0.23719165085388993 0.21610169491525424 0.24222222222222223 0.23863636363636365 0.3046683046683047 0.2692307692307692 0.25475285171102663 0.17699115044247787 0.2169811320754717 0.23333333333333334 0.2777777777777778 
6307
1569
307
0.248771