~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;
}
작성�: Yggdrasil










