U E D R , A S I H C RSS

Hardcore Cpp Study/첫숙제/Overloading/김아영

~cpp 
#include <iostream>
using namespace std;

const int MAX = 20;

int main()
{
	int board[MAX][MAX]={0,};
	int x, y ;
	int garo, sero;
	char direction[MAX];
	int total=0;
	int count =0 ;
	int bang =0;

	cout << "판의 크기를 입력하세요(행, 열) : " ;
	cin >> sero >> garo ;

	cout << "처음 시작 위치를 입력하세요(행, 열) : " ;
	cin >> y >> x ;

	cout << "방향을 입력하세요(0은 북쪽방향, 시계 방향으로 1~7, 끝내기 999) : " ;
	for(int D=0;D<MAX;D++)
	{	
		cin >> direction[D];
		count++;

		if(direction[D-2]=='9' && direction[D-1]=='9' && direction[D]=='9')	
		{
			count-=3 ;
			break;
		}
	}
	
	board[x][y]=1;

	for(bang = 0 ; bang<count ; bang++)
	{
		switch(direction[bang])
		{
		case '0' : y--;
				break;

		case '1' : x++;
			   y--;
				break;
		
		case '2' : x++;
				break;
		
		case '3' : x++;
			   y++;
				break;
		
		case '4' : y++;
				break;
		
		case '5' : x--;
			   y++;	
				break;
		
		case '6' : x--;
				break;
		
		case '7' : x--;
			   y--;
				break;
		}
		
		if(x<0)
			x=garo-1;
		else if(x==garo)
			x=0;
		if(y<0)
			y=sero-1;
		else if(y==sero)
			y=0;
		
		board[x][y]++;
		total++;
	}
		
	for(int i=0;i<sero;i++)
	{
		for(int j=0;j<garo;j++)
			cout << board[j][i] << "\t" ;
		cout << endl ;
	}

	cout << "총 이동 횟수는 " << total << "입니다. " << endl ;

	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:21
Processing time 0.0099 sec