#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TOTAL_CLASSES 10 // 班の数
#define MAX_POINTS 5 // 1つの班に与えられる最大得点
#define MAX_TOTAL_POINTS 10 // 合計得点の上限
int main() {
int my_class; // 自分の班の番号
int scores[TOTAL_CLASSES]; // 各班への得点
int total_points = 0; // 合計得点
int i; // ループ用変数
// 自分の班番号を入力
printf("自分の班の番号を入力してください (0〜%d): ", TOTAL_CLASSES
- 1);
if (my_class < 0 || my_class >= TOTAL_CLASSES) {
return 1; // 異常終了
}
// 乱数の種を初期化
// 初期化
for (i = 0; i < TOTAL_CLASSES; i++) {
scores[i] = 0;
}
// ランダムな得点を生成
for (i = 0; i < TOTAL_CLASSES; i++) {
if (i == my_class) {
scores[i] = 0; // 自分の班は必ず0点
continue;
}
if (total_points < MAX_TOTAL_POINTS) {
// 班に割り振ることができる得点の最大値を計算
int remaining_points = MAX_TOTAL_POINTS - total_points;
int max_points_for_class = remaining_points < MAX_POINTS ? remaining_points : MAX_POINTS;
// 班の得点を乱数で決定
scores
[i
] = rand() % (max_points_for_class
+ 1); total_points += scores[i];
} else {
scores[i] = 0; // 残りの得点がない場合は0点
}
}
// 結果を表示
for (i = 0; i < TOTAL_CLASSES; i++) {
printf("班 %d: %d 点\n", i
, scores
[i
]); }
printf("合計得点: %d 点\n", total_points
);
return 0; // 正常終了
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgVE9UQUxfQ0xBU1NFUyAxMCAgLy8g54+t44Gu5pWwCiNkZWZpbmUgTUFYX1BPSU5UUyA1ICAgICAgLy8gMeOBpOOBruePreOBq+S4juOBiOOCieOCjOOCi+acgOWkp+W+l+eCuQojZGVmaW5lIE1BWF9UT1RBTF9QT0lOVFMgMTAgIC8vIOWQiOioiOW+l+eCueOBruS4iumZkAoKaW50IG1haW4oKSB7CiAgICBpbnQgbXlfY2xhc3M7ICAgICAgICAgICAgICAgIC8vIOiHquWIhuOBruePreOBrueVquWPtwogICAgaW50IHNjb3Jlc1tUT1RBTF9DTEFTU0VTXTsgICAvLyDlkITnj63jgbjjga7lvpfngrkKICAgIGludCB0b3RhbF9wb2ludHMgPSAwOyAgICAgICAgLy8g5ZCI6KiI5b6X54K5CiAgICBpbnQgaTsgICAgICAgICAgICAgICAgICAgICAgIC8vIOODq+ODvOODl+eUqOWkieaVsAoKICAgIC8vIOiHquWIhuOBruePreeVquWPt+OCkuWFpeWKmwogICAgcHJpbnRmKCLoh6rliIbjga7nj63jga7nlarlj7fjgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYQgKDDjgJwlZCk6ICIsIFRPVEFMX0NMQVNTRVMgLSAxKTsKICAgIHNjYW5mKCIlZCIsICZteV9jbGFzcyk7CgogICAgaWYgKG15X2NsYXNzIDwgMCB8fCBteV9jbGFzcyA+PSBUT1RBTF9DTEFTU0VTKSB7CiAgICAgICAgcHJpbnRmKCLjgqjjg6njg7w6IOeEoeWKueOBquePreeVquWPt+OBp+OBmeOAglxuIik7CiAgICAgICAgcmV0dXJuIDE7ICAvLyDnlbDluLjntYLkuoYKICAgIH0KCiAgICAvLyDkubHmlbDjga7nqK7jgpLliJ3mnJ/ljJYKICAgIHNyYW5kKHRpbWUoTlVMTCkpOwoKICAgIC8vIOWIneacn+WMlgogICAgZm9yIChpID0gMDsgaSA8IFRPVEFMX0NMQVNTRVM7IGkrKykgewogICAgICAgIHNjb3Jlc1tpXSA9IDA7CiAgICB9CgogICAgLy8g44Op44Oz44OA44Og44Gq5b6X54K544KS55Sf5oiQCiAgICBmb3IgKGkgPSAwOyBpIDwgVE9UQUxfQ0xBU1NFUzsgaSsrKSB7CiAgICAgICAgaWYgKGkgPT0gbXlfY2xhc3MpIHsKICAgICAgICAgICAgc2NvcmVzW2ldID0gMDsgIC8vIOiHquWIhuOBruePreOBr+W/heOBmjDngrkKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQoKICAgICAgICBpZiAodG90YWxfcG9pbnRzIDwgTUFYX1RPVEFMX1BPSU5UUykgewogICAgICAgICAgICAvLyDnj63jgavlibLjgormjK/jgovjgZPjgajjgYzjgafjgY3jgovlvpfngrnjga7mnIDlpKflgKTjgpLoqIjnrpcKICAgICAgICAgICAgaW50IHJlbWFpbmluZ19wb2ludHMgPSBNQVhfVE9UQUxfUE9JTlRTIC0gdG90YWxfcG9pbnRzOwogICAgICAgICAgICBpbnQgbWF4X3BvaW50c19mb3JfY2xhc3MgPSByZW1haW5pbmdfcG9pbnRzIDwgTUFYX1BPSU5UUyA/IHJlbWFpbmluZ19wb2ludHMgOiBNQVhfUE9JTlRTOwoKICAgICAgICAgICAgLy8g54+t44Gu5b6X54K544KS5Lmx5pWw44Gn5rG65a6aCiAgICAgICAgICAgIHNjb3Jlc1tpXSA9IHJhbmQoKSAlIChtYXhfcG9pbnRzX2Zvcl9jbGFzcyArIDEpOwogICAgICAgICAgICB0b3RhbF9wb2ludHMgKz0gc2NvcmVzW2ldOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNjb3Jlc1tpXSA9IDA7ICAvLyDmrovjgorjga7lvpfngrnjgYzjgarjgYTloLTlkIjjga8w54K5CiAgICAgICAgfQogICAgfQoKICAgIC8vIOe1kOaenOOCkuihqOekugogICAgcHJpbnRmKCJcbuODqeODs+ODgOODoOOBquW+l+eCuee1kOaenDpcbiIpOwogICAgZm9yIChpID0gMDsgaSA8IFRPVEFMX0NMQVNTRVM7IGkrKykgewogICAgICAgIHByaW50Zigi54+tICVkOiAlZCDngrlcbiIsIGksIHNjb3Jlc1tpXSk7CiAgICB9CgogICAgcHJpbnRmKCLlkIjoqIjlvpfngrk6ICVkIOeCuVxuIiwgdG90YWxfcG9pbnRzKTsKCiAgICByZXR1cm4gMDsgIC8vIOato+W4uOe1guS6hgp9Cg==