2019-10-21 21일차 2차원 배열 (좌표<------> 배열의인덱스)
Console Programming/C# Console 2019. 10. 23. 18:18
Program.cs
namespace Syntax01
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
App.cs
using System;
namespace Syntax01
{
public class App
{
public App()
{
int[] arr = ConvertIndexToCoordiation(1, 0);
Console.WriteLine("({0}, {1})", arr[0], arr[1]);
int[,] arr2 = ConvertIndexToCoordiation2(1, 0);
Console.WriteLine("({0}, {1})", arr2[0,0], arr2[0,1]);
int[] arr3 = ConvertCoordinationToIndex(3, 0);
Console.WriteLine("[{0}, {1}]", arr3[0], arr3[1]);
}
//배열의인덱스를 좌표로 변환해서 1차원 배열에 담음
public int[] ConvertIndexToCoordiation(int row, int col)
{
int[] arr = new int[2];
arr[0] = col;
arr[1] = -row;
return arr;
}
//배열의인덱스를 좌표로 변환해서 2차원 배열에 담음
public int[,] ConvertIndexToCoordiation2(int row, int col)
{
int[,] arr = new int[1,2];
arr[0,0] = col;
arr[0,1] = -row;
return arr;
}
//좌표를 배열의인덱스로 변환해서 1차원 배열에 담음
public int[] ConvertCoordinationToIndex(int x, int y)
{
int[] arr = new int[2];
arr[0] = -y;
arr[1] = x;
return arr;
}
}
}
'Console Programming > C# Console' 카테고리의 다른 글
백준 6679 싱기한 네자리 숫자 (0) | 2019.10.24 |
---|---|
2019-10-21 21일차 2차원 배열(2) 좌표를 인덱스로 변환하고 캐릭터 움직이기 (0) | 2019.10.24 |
백준 2167 (0) | 2019.10.22 |
2019-10-18 20일차 롤 챔피언 Attack메시지 출력 (json, Dictionary, 클래스상속사용) (0) | 2019.10.18 |
2019-10-17 19일차 클래스의 상속 뽑기상자, json사용, get;set사용 , rand.Next사용 (0) | 2019.10.18 |