fork download
  1. #include <stdio.h>
  2. #define SIZEX 25
  3. #define SIZEY 7
  4. // prototype
  5. void mysort();
  6. void disp();
  7.  
  8. int a[SIZEX + 1][SIZEY] = {0}, cnt = 0, ord[6];
  9.  
  10. void mysort()
  11. {
  12. int i, j, k, t;
  13. // 科目毎の合計点でsort
  14. for ( i = 1; i < 6; ++i) {
  15. // printf("%d\n", i);
  16. for ( j = i + 1; j < 6; ++j) {
  17. if (a[cnt][i] < a[cnt][j]) {
  18. for (k = 0; k <= cnt; ++k) {
  19. t = a[k][i];
  20. a[k][i] = a[k][j] ;
  21. a[k][j] = t ;
  22. }
  23. t = ord[i];
  24. ord[i] = ord[j];
  25. ord[j] = t;
  26. }
  27. }
  28. }
  29. // 学生毎の合計点でsort
  30. for ( i = 0; i < cnt; ++i) {
  31. for ( j = 0; j < cnt; ++j) {
  32. if (a[i][6] < a[j][6]) {
  33. for ( k = 0; k < 7; ++k) {
  34. t = a[i][k];
  35. a[i][k] = a[j][k] ;
  36. a[j][k] = t;
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
  43. void disp()
  44. {
  45. int i, j;
  46. printf(" 番号 ");
  47. for ( i = 1; i <= 5; ++i)
  48. printf(" 問%d", ord[i]);
  49. printf(" 合計\n");
  50. for ( i = 0; i < cnt; ++i) {
  51. printf("%6d", a[i][0]);
  52. for ( j = 1; j < 6; ++j) printf("%6d", a[i][j]);
  53. printf("%6d\n", a[i][6]);
  54. }
  55.  
  56. printf(" 合計");
  57. for ( j = 1; j < 6; ++j)
  58. printf("%6d", a[cnt][j]);
  59. printf("%6d\n", a[cnt][6]);
  60. }
  61.  
  62. int main()
  63. {
  64. FILE *fp;
  65. int i, j, *p = *a;
  66.  
  67. // データ読込
  68. fp = fopen("seiseki.dat", "r");
  69. for (p = *a; fscanf(fp, "%d", p) == 1; ++p)
  70. if (++cnt % 6 == 0)++p;
  71. cnt /= 6;
  72. for ( i = 1; i <= 5; ++i)ord[i] = i;
  73.  
  74. // 合計計算
  75. for ( i = 0; i < cnt; ++i) {
  76. for ( j = 1; j < 6; ++j) {
  77. a[i][6] += a[i][j];
  78. a[cnt][j] += a[i][j];
  79. a[cnt][6] += a[i][j];
  80. }
  81. }
  82.  
  83. // 表示
  84. printf("整列前\n");
  85. disp();
  86. mysort();
  87. printf("整列後\n");
  88. disp();
  89.  
  90. return 0;
  91. }
  92.  
Runtime error #stdin #stdout 0.01s 1804KB
stdin
Standard input is empty
stdout
Standard output is empty