U E D R , A S I H C RSS

숫자야구/곽세환

~cpp 
#include <iostream>
#include <ctime>

using namespace std;

int main()
{
	int input;
	int ques[3], ans[3];
	int strike = 0, ball = 0;
	int i, j;

	srand(time(0));
	ques[0] = rand() % 10;
	do
	{
		ques[1] = rand() % 10;
	}
	while (ques[1] == ques[0]);
	do
	{
		ques[2] = rand() % 10;
	}
	while (ques[2] == ques[0] || ques[2] == ques[1]);

	for (i = 0; i < 3; i++)
		cout << ques[i];
	cout << endl;
	do
	{
		strike = 0;
		ball = 0;
		cout << "숫자입력 : ";
		cin >> input;
		ans[0] = input / 100;
		ans[1] = (input % 100) / 10;
		ans[2] = input % 10;
	
		for (i = 0; i < 3; i++)
			for (j = 0; j < 3; j++)
				if (ques[i] == ans[j])
				{
					if (i == j)
						strike++;
					else
						ball++;
				}
		cout << strike << "S" << ball << "B" << endl;
	} while (strike != 3);
	cout << "OUT" << endl;

	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:16
Processing time 0.0088 sec