#include <stdio.h>
struct GDATA {
int bango;
char sei[11];
char mei[11];
int tokuten;
};
int main(void)
{
FILE *fp;
int ret;
int count;
struct GDATA a[100];
int bango;
int i;
int j;
int k;
int found;
int searchCount;
/* read */
fp
= fopen("data-1.dat", "r"); if (fp == NULL) {
printf("%s\n", "data-1.dat OPEN ERROR!"); return 1;
}
i = 0;
while (1) {
ret
= fscanf(fp
, "%4d%10s%10s%3d", &a
[i
].
bango, a
[i
].
sei, a
[i
].
mei, &a
[i
].
tokuten); if (ret == EOF) {
break;
}
i++;
}
count = i;
/* sort */
{
struct GDATA t;
for(i=0; i<count; i++) {
for(j=i+1; j<count; j++) {
if(a[i].bango>a[j].bango) {
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
}
while (1) {
/* input */
ret
= fscanf(stdin
, "%d", &bango
); if (ret == EOF) {
break;
}
/* search */
i = 0;
j = count - 1;
searchCount = 0;
while (1) {
if (i > j) {
found = 0;
break;
}
k = ((j - i) >> 1) + i;
searchCount++;
if (bango < a[k].bango) {
j = k - 1;
} else {
if (bango > a[k].bango) {
i = k + 1;
} else {
found = 1;
break;
}
}
}
/* message */
if (found) {
printf("%d番%s %s 得点= %d点 探索回数= %d回\n", a
[k
].
bango, a
[k
].
sei, a
[k
].
mei, a
[k
].
tokuten, searchCount
); } else {
printf("%d番なし 探索回数= %d回\n", bango
, searchCount
); }
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgR0RBVEEgewogIGludCBiYW5nbzsKICBjaGFyIHNlaVsxMV07CiAgY2hhciBtZWlbMTFdOwogIGludCB0b2t1dGVuOwp9OwoKaW50IG1haW4odm9pZCkKewogIEZJTEUgKmZwOwogIGludCByZXQ7CiAgaW50IGNvdW50OwogIHN0cnVjdCBHREFUQSBhWzEwMF07CiAgaW50IGJhbmdvOwogIGludCBpOwogIGludCBqOwogIGludCBrOwogIGludCBmb3VuZDsKICBpbnQgc2VhcmNoQ291bnQ7CgogIC8qIHJlYWQgKi8KICBmcCA9IGZvcGVuKCJkYXRhLTEuZGF0IiwgInIiKTsKICBpZiAoZnAgPT0gTlVMTCkgewogICAgcHJpbnRmKCIlc1xuIiwgImRhdGEtMS5kYXQgT1BFTiBFUlJPUiEiKTsKICAgIHJldHVybiAxOwogIH0KICBpID0gMDsKICB3aGlsZSAoMSkgewogICAgcmV0ID0gZnNjYW5mKGZwLCAiJTRkJTEwcyUxMHMlM2QiLCAmYVtpXS5iYW5nbywgYVtpXS5zZWksIGFbaV0ubWVpLCAmYVtpXS50b2t1dGVuKTsKICAgIGlmIChyZXQgPT0gRU9GKSB7CiAgICAgIGJyZWFrOwogICAgfQogICAgaSsrOwogIH0KICBmY2xvc2UoZnApOwoKICBjb3VudCA9IGk7CgogIC8qIHNvcnQgKi8KICB7CiAgICBzdHJ1Y3QgR0RBVEEgdDsKICAgIGZvcihpPTA7IGk8Y291bnQ7IGkrKykgewogICAgICBmb3Ioaj1pKzE7IGo8Y291bnQ7IGorKykgewogICAgICAgIGlmKGFbaV0uYmFuZ28+YVtqXS5iYW5nbykgewogICAgICAgICAgdD1hW2ldOwogICAgICAgICAgYVtpXT1hW2pdOwogICAgICAgICAgYVtqXT10OwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KCiAgd2hpbGUgKDEpIHsKICAgIC8qIGlucHV0ICovCiAgICByZXQgPSBmc2NhbmYoc3RkaW4sICIlZCIsICZiYW5nbyk7CiAgICBpZiAocmV0ID09IEVPRikgewogICAgICBicmVhazsKICAgIH0KCiAgICAvKiBzZWFyY2ggKi8KICAgIGkgPSAwOwogICAgaiA9IGNvdW50IC0gMTsKICAgIHNlYXJjaENvdW50ID0gMDsKICAgIHdoaWxlICgxKSB7CiAgICAgIGlmIChpID4gaikgewogICAgICAgIGZvdW5kID0gMDsKICAgICAgICBicmVhazsKICAgICAgfQogICAgICBrID0gKChqIC0gaSkgPj4gMSkgKyBpOwogICAgICBzZWFyY2hDb3VudCsrOwogICAgICBpZiAoYmFuZ28gPCBhW2tdLmJhbmdvKSB7CiAgICAgICAgaiA9IGsgLSAxOwogICAgICB9IGVsc2UgewogICAgICAgIGlmIChiYW5nbyA+IGFba10uYmFuZ28pIHsKICAgICAgICAgIGkgPSBrICsgMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZm91bmQgPSAxOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICB9CiAgICB9CgogICAgLyogbWVzc2FnZSAqLwogICAgaWYgKGZvdW5kKSB7CiAgICAgIHByaW50ZigiJWTnlaolcyAlcyDlvpfngrk9ICVk54K5IOaOoue0ouWbnuaVsD0gJWTlm55cbiIsIGFba10uYmFuZ28sIGFba10uc2VpLCBhW2tdLm1laSwgYVtrXS50b2t1dGVuLCBzZWFyY2hDb3VudCk7CiAgICB9IGVsc2UgewogICAgICBwcmludGYoIiVk55Wq44Gq44GXIOaOoue0ouWbnuaVsD0gJWTlm55cbiIsIGJhbmdvLCBzZWFyY2hDb3VudCk7CiAgICB9CiAgfQoKICByZXR1cm4gMDsKfQ==