// co_112_585.c
// ##############################################################
// ##
// ## このプログラムはとっても危険かも知れません!!
// ##
// ## 実行中、PCにかなり負荷がかかった後
// ## 勝手に電源が落ちるかも知れません(熱暴走?)
// ## 実行される方は自己責任で。
// ##
// ##############################################################
#include <stdio.h>
#include <stdlib.h>
int check(void);
void make_code(int n);
int main(int argc, char *argv[])
{
int min_if;
int max_if;
int n;
// 初期値 = 1 で開始し、2倍してコンパイルを試していく
for (min_if = 1; min_if < 0x40000000; min_if *= 2) {
fprintf(stderr
, "testing %d", min_if
); make_code(min_if);
if (check()) { //error
break;
}
}
if (min_if >= 0x40000000) {
fprintf(stderr
, "%dまで試したがコンパイル出来た\n", 0x20000000); fprintf(stderr
, "(これ以上は当プログラムでは試せない)\n"); return 0;
}
// 挟みうちでコンパイルを試していく
max_if = min_if;
min_if /= 2;
while (1) {
n = (max_if + min_if) / 2;
make_code(n);
if (check()) { //error
max_if = n;
} else {
min_if = n;
}
if (max_if - min_if <= 1) {
break;
}
}
// 結果
printf("%d個までは大丈夫\n", min_if
); printf("%d個でコンパイルエラー\n", max_if
);
return 0;
}
// if ~ else を n 個作成
void make_code(int n)
{
FILE *fp;
int i;
fp
= fopen("test.c", "w"); fprintf(fp
, "int main(int argc, char *argv[])\n"); fprintf(fp
, " case 1:return 1;\n"); for (i = 2; i <= n; i++) {
fprintf(fp
, " case %d:return %d;\n", i
, i
); }
}
// make_code(); で生成された test.c がコンパイル出来るかテスト
int check(void)
{
int res;
res
= system("gcc -c -Wall test.c"); if (res == 0) {
}
return res;
}
// End of co_112_585.c
Ly8gY29fMTEyXzU4NS5jCi8vICMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCi8vICMjCi8vICMjICDjgZPjga7jg5fjg63jgrDjg6njg6Djga/jgajjgaPjgabjgoLljbHpmbrjgYvjgoLnn6Xjgozjgb7jgZvjgpMhIQovLyAjIwovLyAjIyAg5a6f6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OBn1xuIiwgMHgyMDAwMDAwMCk7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICIo44GT44KM5Lul5LiK44Gv5b2T44OX44Ot44Kw44Op44Og44Gn44Gv6Kmm44Gb44Gq44GEKVxuIik7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICAvLyDmjJ/jgb/jgYbjgaHjgafjgrPjg7Pjg5HjgqTjg6vjgpLoqabjgZfjgabjgYTjgY8KICAgIG1heF9pZiA9IG1pbl9pZjsKICAgIG1pbl9pZiAvPSAyOwogICAgd2hpbGUgKDEpIHsKICAgICAgICBuID0gKG1heF9pZiArIG1pbl9pZikgLyAyOwogICAgICAgIGZwcmludGYoc3RkZXJyLCAidGVzdGluZyAlZCIsIG4pOwogICAgICAgIG1ha2VfY29kZShuKTsKICAgICAgICBpZiAoY2hlY2soKSkgeyAgICAgICAgICAvL2Vycm9yCiAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiLi4uIOOCs+ODs+ODkeOCpOODq+WkseaVl1xuIik7CiAgICAgICAgICAgIG1heF9pZiA9IG47CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZnByaW50ZihzdGRlcnIsICIuLi4g44Kz44Oz44OR44Kk44Or5oiQ5YqfXG4iKTsKICAgICAgICAgICAgbWluX2lmID0gbjsKICAgICAgICB9CiAgICAgICAgaWYgKG1heF9pZiAtIG1pbl9pZiA8PSAxKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KCiAgICAvLyDntZDmnpwKICAgIHByaW50ZigiXG5cbiIpOwogICAgcHJpbnRmKCIlZOWAi+OBvuOBp+OBr+Wkp+S4iOWkq1xuIiwgbWluX2lmKTsKICAgIHByaW50ZigiJWTlgIvjgafjgrPjg7Pjg5HjgqTjg6vjgqjjg6njg7xcbiIsIG1heF9pZik7CgogICAgcmV0dXJuIDA7Cn0KCi8vIGlmIO+9niBlbHNlIOOCkiBuIOWAi+S9nOaIkAp2b2lkIG1ha2VfY29kZShpbnQgbikKewogICAgRklMRSAqZnA7CiAgICBpbnQgaTsKCiAgICBmcCA9IGZvcGVuKCJ0ZXN0LmMiLCAidyIpOwogICAgZnByaW50ZihmcCwgImludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pXG4iKTsKICAgIGZwcmludGYoZnAsICJ7XG4iKTsKICAgIGZwcmludGYoZnAsICIgIHN3aXRjaChhcmdjKSB7XG4iKTsKICAgIGZwcmludGYoZnAsICIgICAgY2FzZSAxOnJldHVybiAxO1xuIik7CiAgICBmb3IgKGkgPSAyOyBpIDw9IG47IGkrKykgewogICAgICAgIGZwcmludGYoZnAsICIgICAgY2FzZSAlZDpyZXR1cm4gJWQ7XG4iLCBpLCBpKTsKICAgIH0KICAgIGZwcmludGYoZnAsICIgICAgZGVmYXVsdDpicmVhaztcbiIpOwogICAgZnByaW50ZihmcCwgIiAgfVxuIik7CiAgICBmcHJpbnRmKGZwLCAiICByZXR1cm4gMDtcbiIpOwogICAgZnByaW50ZihmcCwgIn1cbiIpOwogICAgZmNsb3NlKGZwKTsKfQoKLy8gbWFrZV9jb2RlKCk7IOOBp+eUn+aIkOOBleOCjOOBnyB0ZXN0LmMg44GM44Kz44Oz44OR44Kk44Or5Ye65p2l44KL44GL44OG44K544OICmludCBjaGVjayh2b2lkKQp7CiAgICBpbnQgcmVzOwogICAgcmVzID0gc3lzdGVtKCJnY2MgLWMgLVdhbGwgdGVzdC5jIik7CiAgICBpZiAocmVzID09IDApIHsKICAgICAgICByZW1vdmUoInRlc3QubyIpOwogICAgfQogICAgcmV0dXJuIHJlczsKfQoKLy8gRW5kIG9mIGNvXzExMl81ODUuYwo=