Code/C, C++

가위바위보

Segel 2021. 11. 21. 11:32
#include <iostream>
#include <string>

int main()
{
	srand(time(0));
	int rpsMatrix[3][3] = { {0, -1, 1}, {1, 0, -1}, {-1, 1, 0} };
 
	while (true)
	{
		std::string input;
 		std::getline(std::cin, input);
        
		int c = rand() % 3 + 1;
		int p = input.compare("바위") + 1;
 
		std::cout << "computer: " << c << std::endl;
 
		switch (rpsMatrix[c][p])
		{
		case -1:
			std::cout << "player" << std::endl;
			break;
 
		case 0:
			std::cout << "tie" << std::endl;
			break;
 
		case 1:
			std::cout << "computer" << std::endl;
			break;
		}
	}
}
반응형

'Code > C, C++' 카테고리의 다른 글

scanf 대신 fread 사용 시 참고  (0) 2022.03.26
VS2019 C/C++ IntelliSense 설정  (0) 2021.04.17
malloc() 결과값의 캐스팅  (0) 2020.11.27