U E D R , A S I H C RSS

Number Baseball Game/재니

작성자의 페이지

02 장재니 Genie

소스

~cpp 
#include <iostream>
#include <ctime>
using namespace std;

int main()
{
	int a, b, c, input, x, y, z, ball, strike;
	srand((time(0)));
	a = rand() % 9;
	b = rand() % 9;
	c = rand() % 9;
	while (a == b)
		b = rand() % 9;
	while (c == a || c == b)
		c = rand() % 9;

	cout << "숫자 야구 게임입니다.\n";
	cout << a << b << c << endl;
	while (input != a * 100 + b * 10 + c)
	{
		cin >> input;
		strike = ball = 0;
		if (input < 123 || input > 987)
		{
			cout << "잘못 입력하셨습니다.\n";
			continue;
		}
		x = input / 100;
		y = input / 10 - 10 * x;
		z = input - 100 * x - 10 * y;
		if (a == x) strike++;
		if (b == y) strike++;
		if (c == z) strike++;
		if (a == y || a == z) ball++;
		if (b == x || b == z) ball++;
		if (c == x || c == y) ball++;
		if (strike == 0 && ball == 0)
			cout << "아웃!n";
		else
			cout << strike << " 스트라이크 " << ball << " 볼n";
	}
	cout << "잘 해쓰~ ^_________^\n";
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:52
Processing time 0.0233 sec