U E D R , A S I H C RSS

Scheduled Walk/권정욱

No older revisions available

No older revisions available



ScheduledWalk/권정욱

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

int main(){
	ifstream fin("input.txt");
	ofstream fout("output.txt");
	
	int length;
	int walk[100][100];
	int i, j;
	int x , y;
	char direct;
	int temp;
	
	
	fin >> length;
	for (i = 0; i < length; i++){
		for (j = 0; j < length; j++){
			walk[i][j] = 0;	
		}			// 초기화
	}
	fin >> x;
	fin >> y;

	walk[x][y] = 0;
	while (!fin.eof()){
		int directer = direct - 48;
		if (direct == ' ' || direct =='\n') {
			direct = fin.get();
			continue;
		}
		if (direct == '9') break;
		switch (directer){
		case 1 : 
			x += 1;
			y -= 1;
			break;
		case 2 :
			x +=1;
			break;
		case 3 :
			x += 1;
			y += 1;
			break;
		case 4 :
			y += 1;
			break;
		case 5 :
			x -= 1;
			y += 1;
			break;
		case 6 :
			x -= 1;
			break;
		case 7 :
			x -= 1;
			y -= 1;
			break;
		case 0 :
			y -= 1;
			break;
		}
		if (x < 0) x += length;
		if (x == length) x -= length;
		if (y < 0) y += length;
		if (y == length) y -= length;
		walk[y][x]++;

		direct = fin.get();
	}
	cout << endl;
	
	for (i = 0; i < length; i++){
		for (j = 0; j < length; j++){
			cout << walk[i][j] << " ";
		}
		cout << endl;
	}
	
	
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:59
Processing time 0.0155 sec