U E D R , A S I H C RSS

가위바위보/영동

~cpp 
//가위바위보 승패수 계산 프로그램
#include<iostream.h>
#include<fstream.h>
int gawibawibo(char, char);
void main()
{
	int result;
	int sunho_win=0;
	int sunho_lose=0;
	int sunho_draw=0;
	char name[2][10];
	char sunho;
	char insu;
	char ch;

	//파일 읽음
	ifstream fin("data1.txt");
	fin.getline(name[0], 10);
	fin.getline(name[1], 10);
	while(!fin.eof()){
	fin.get(sunho);
	fin.get(ch);
	fin.get(insu);
	fin.get(ch);
	result=gawibawibo(sunho, insu);
	
	
	//결과를 계산
	if(result==0)
		sunho_win++;
	else if(result==1)
		sunho_draw++;
	else 
		sunho_lose++;}

	//결과를 출력
	cout<<"sunho의 승수: "<<sunho_win<<endl;
	cout<<"비긴 수: "<<sunho_draw<<endl;
	cout<<"sunho의 패수: "<<sunho_lose<<endl;
	cout<<"insu의 승수: "<<sunho_lose<<endl;
	cout<<"비긴 수: "<<sunho_draw<<endl;
	cout<<"insu의 패수: "<<sunho_win<<endl;
}
int gawibawibo(char sunho, char insu)
{
	int result;
	if(sunho=='0' && insu=='2')
		result=0; //sunho가 이긴 경우는 0을 대입
	else if(sunho=='2' && insu=='0')
		result=2; //insu가 이긴 경우는 2을 대입
	else if(sunho=='2' && insu=='1')
		result=0; //sunho가 이긴 경우는 0을 대입
	else if(sunho=='1' && insu=='0')
		result=0; //sunho가 이긴 경우는 0을 대입
	else if(sunho=='0' && insu=='1')
		result=2; //insu가 이긴 경우는 2을 대입
	else if(sunho=='1' && insu=='2')
		result=2; //insu가 이긴 경우는 2을 대입
	else if(sunho=='1' && insu=='1')
		result=1; //비긴 경우에는 1 대입
	else if(sunho=='2' && insu=='2')
		result=1; //비긴 경우에는 1 대입
	else if(sunho=='0' && insu=='0')
		result=1; //비긴 경우에는 1 대입


	return result;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:39
Processing time 0.0141 sec