結果

問題 No.355 数当てゲーム(2)
ユーザー hanorver
提出日時 2016-04-02 14:48:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 67,024 KB
実行使用メモリ 25,844 KB
平均クエリ数 27.38
最終ジャッジ日時 2024-07-16 09:37:24
合計ジャッジ時間 11,228 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 48
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:27: warning: ‘pre’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |                         d = pre;
      |                         ~~^~~~~

ソースコード

diff #

#include<iostream>
#include<climits>
#include<vector>
#include<algorithm>

void print(int a, int b, int c, int d) {
	std::cout << a << " " << b << " " << c << " " << d << std::endl;
}

int main() {
	int a = 1, b = 2, c = 3, d = 4;
	int hit, blow;

	print(a, b, c, d);
	std::cin >> hit >> blow;

	if (hit == 4) return 0;

	int h, bl, pre;
	while(d < 10) {
		print(a, b, c, d);
		std::cin >> h >> bl;
		if (h == 4) return 0;
		if (h + bl > hit + blow) {
			hit = h;
			blow = b;
			break;
		}
		if (h + bl < hit + blow) {
			d = pre;
			break;
		}	
		pre = d;
		d++;
	}

	while (c < 10) {
		print(a, b, c, d);
		std::cin >> h >> bl;
		if (h == 4) return 0;
		if (h + bl > hit + blow) {
			hit = h;
			blow = b;
			break;
		}
		if (h + bl < hit + blow) {
			c = pre;
			break;
		}
		
		pre = c;
		c++;
	}
	while (b < 10) {
		print(a, b, c, d);
		std::cin >> h >> bl;
		if (h == 4) return 0;
		if (h + bl > hit + blow) {
			hit = h;
			blow = b;
			break;
		}
		if (h + bl < hit + blow) {
			b = pre;
			break;
		}
		
		pre = b;
		b++;
	}
	while (a < 10) {
		print(a, b, c, d);
		std::cin >> h >> bl;
		if (h == 4) return 0;
		if (h + bl > hit + blow) {
			hit = h;
			blow = b;
			break;
		}
		if (h + bl < hit + blow) {
			a = pre;
			break;
		}
		
		pre = a;
		a++;
	}

	std::vector<int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	v.push_back(d);

	std::sort(v.begin(), v.end());

	do {
		print(v[0], v[1], v[2], v[3]);
		std::cin >> h >> bl;
		if (h == 4) return 0;
	} while (std::next_permutation(v.begin(), v.end()));

	return 0;
}
0