U E D R , A S I H C RSS

숫자야구/문원명

No older revisions available

No older revisions available



숫자야구

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

void main()
{
	int ans[3];
	int input[3];
	int strike,ball;
	srand(time(0)); 
	ans[0] = rand()%10;
	
	do 
	{
		ans[1] = rand()%10;
	} while(ans[1] == ans[0]);

	do
	{
		ans[2] = rand()%10;
	} while((ans[2] == ans[0]) || (ans[2] == ans[1]));
	
	cout << ans[0] << "\t" << ans[1] << "\t" << ans[2] << endl << endl;
	
	do
	{
		cin >> input[0] >> input[1] >> input[2];
		strike=0;
		ball=0;
		for(int i=0; i < 3; i++)
		{
			for(int j=0; j < 3; j++)
			{
				if (ans[i] == input[j])
				{
					if (i==j) strike++;
					else ball++;
				}
			}
		}
		cout << "strike = " << strike << "\t ball = " << ball << endl;
	}while(strike != 3);
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:16
Processing time 0.0289 sec