티스토리 뷰
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pad.h"
void rotateArr(int numberPad[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE], int arraySize, int direction, int isUpAndDown);
/**
* 이동문자열을 추출하는 기능
*
* @param[out] rotationStr 이동문자열
* @param[in] inputData 입력데이터(문자열)
*/
void extractRotationStr(char rotationStr[MAX_DATA_LENGTH], char inputData[MAX_DATA_LENGTH]) {
memset(rotationStr, 0, sizeof(char) * MAX_DATA_LENGTH);
////////////////////////// ---------------->
int idx = 0;
for(int i=1; i<strlen(inputData); i=i+2) {
if(inputData[i] == 'U' || inputData[i] == 'D' || inputData[i] == 'L' || inputData[i] == 'R') {
if(inputData[i-1] != '0') {
strncpy(&rotationStr[idx], &inputData[i-1], sizeof(char)*2);
idx = idx + 2;
}
}
}
/////////////////////////// <--------------
}
/**
* 숫자패드를 이동시키는 기능
*
* @param[in,out] numberPad 숫자패드/이동된 숫자패드
* @param[in] arraySize 배열 크기
* @param[in] rotationStr 이동문자열
*/
void rotateNumberPad(int numberPad[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE], int arraySize, char rotationStr[MAX_DATA_LENGTH]) {
////////////////////////// ---------------->
// 최종 이동할 개수 계산
int moveRowCnt = 0;
int moveColCnt = 0;
for(int i=1; i<strlen(rotationStr); i=i+2) {
switch(rotationStr[i]) {
case 'U': moveRowCnt = moveRowCnt - (rotationStr[i-1] -'0'); break;
case 'D': moveRowCnt = moveRowCnt + (rotationStr[i-1] -'0'); break;
case 'L': moveColCnt = moveColCnt - (rotationStr[i-1] -'0'); break;
case 'R': moveColCnt = moveColCnt + (rotationStr[i-1] -'0'); break;
}
}
// 각 원소별 이동위치 계산
int tmpNumberPad[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE];
memset(tmpNumberPad, 0, sizeof(int)*MAX_ARRAY_SIZE*MAX_ARRAY_SIZE);
memcpy(tmpNumberPad, numberPad, sizeof(int)*MAX_ARRAY_SIZE*MAX_ARRAY_SIZE);
int row = 0;
int col = 0;
for(int i=0; i<arraySize; i++) {
for(int j=0; j<arraySize; j++) {
// 최종 행위치
row = i + moveRowCnt;
if (row < 0)
row = row + arraySize;
else if (row >= arraySize)
row = row % arraySize;
// 최종 열위치
col = j + moveColCnt;
if (col < 0)
col = col + arraySize;
else if (col >= arraySize)
col = col % arraySize;
numberPad[row][col] = tmpNumberPad[i][j];
}
}
/////////////////////////// <--------------
}
/**
* 배열을 이동시키는 기능 (솔루션용 기능, 제공파일에 없음)
*
* @param[in,out] numberPad 배열/이동된 배열
* @param[in] arraySize 배열 크기
* @param[in] direction 방향(+또는-)
* @param[in] isUpAndDown 위,아래,왼쪽,오른쪽(0또는1)
*/
void rotateArr(int numberPad[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE], int arraySize, int direction, int isUpAndDown) {
int tmpNumberPad[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE];
memcpy(tmpNumberPad, numberPad, sizeof(int) * MAX_ARRAY_SIZE * MAX_ARRAY_SIZE);
for(int i=0; i<arraySize; i++) {
for(int j=0; j<arraySize; j++) {
if(isUpAndDown == 1) numberPad[(arraySize*arraySize+direction+i)%arraySize][j] = tmpNumberPad[i][j];
else numberPad[i][(arraySize*arraySize+direction+j)%arraySize] = tmpNumberPad[i][j];
}
}
}
'Test > C' 카테고리의 다른 글
Dedup (0) | 2019.05.01 |
---|---|
center number (크기 기준) (0) | 2019.04.28 |
isdigit(), sprintf(), atoi() (0) | 2019.04.16 |
MingGW 컴파일러 데이터타입 싸이즈 (0) | 2019.04.07 |
파일 입출력 (0) | 2019.01.07 |
- Total
- Today
- Yesterday
- 배열
- vmware
- cloud-init
- dp-1
- 읽어오기
- fromkeys
- vmware.powercli
- 3par
- 정렬
- LIST
- set()
- 스토리지
- 대소문자
- oracle
- dp-2
- EXA
- exadata
- artandculture
- 중복제거
- powercli
- 변수화
- sysprep
- Join
- dezoomify
- storage
- 차집합
- virt-sysprep
- insert
- powershell
- 부동없이
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |