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

int tri(int a);

void main()
{
	srand(time(0)); 	

	int key_first = rand()%10;
	int key_second = rand()%10;
	while (key_first == key_second)
		key_second= rand()%10;
	int key_third = rand()%10;
	while (key_first == key_third || key_second == key_third)
		key_third = rand()%10;



	int i,strike=0 , ball=0;

	int key = key_first*100 + key_second*10 + key_third;

	cout << key_first << key_second << key_third << endl;
	while (i != key)
	{
		cout << "수를 입력 하세요(3자리) = ";
		cin >> i;
		int input_first = i / 100;
		int input_second = (i - 100 *(i /100))/10;
		int input_third = i-(100*(i/100)) - (10*((i - 100 *(i /100))/10));

		if (key_first == input_first)
			strike ++;
		if (key_second == input_second)
			strike ++;
		if (key_third == input_third)
			strike ++;
		if (key_first == input_second)
			ball ++;
		if (key_first == input_third)
			ball ++;
		if (key_second == input_third)
			ball ++;
		if (key_second == input_first)
			ball ++;
		if (key_third == input_first)
			ball ++;
		if (key_third == input_second)
			ball ++;

		cout << strike << "스트라이크 " << ball << "볼" << endl;
		strike = 0;
		ball = 0;
		
	}

}



Retrieved from http://wiki.zeropage.org/wiki.php/숫자야구/장창재
last modified 2021-02-07 05:30:16