변경이력

돌아가기
4 91개 문자 삭제

2015/10/07 20:33

서영주

```{.cpp} #include <iostream> using namespace std; void getInput(int ** arr, int row, int column); int main() { int row=0, column=0; cin >> row >> column; int ** arr = new int *[row]; for(int i=0; i<row; i++) { arr[i] = new int [column]; } getInput(arr, row, column); for(int i=0; i<row; i++) { for(int j=0; j<column; j++) { cout << arr[i][j] << " "; } cout << endl; } return 0; } void getInput(int ** arr, int row, int column) { int inputValue =-1; int start_i = 0, start_j = 0; int last_i = row-1, last_j = column-1; int finalValue = (row*column)-1; while(inputValue!=finalValue){ for(int j=start_j; j<=last_j; j++) { inputValue+=1; arr[start_i][j] = inputValue; } if(inputValue==finalValue) break; for(int i=start_i+1; i<=last_i; i++) { inputValue+=1; arr[i][last_j] = inputValue; } if(inputValue==finalValue) break; for(int j=last_j-1; j>=start_j; j--) { inputValue+=1; arr[last_i][j] = inputValue; } if(inputValue==finalValue) break; for(int i=last_i-1; i>=start_i+1; i--) { inputValue+=1; arr[i][start_j] = inputValue; cout << "(" << i << "," << start_j << ")" << "/ InputValue = " << inputValue << endl; } if(inputValue==finalValue) break; start_i+=1; start_j+=1; last_i-=1; last_j-=1; } } ```
```{.cpp} #include <iostream> using namespace std; void getInput(int ** arr, int row, int column); int main() { int row=0, column=0; cin >> row >> column; int ** arr = new int *[row]; for(int i=0; i<row; i++) { arr[i] = new int [column]; } getInput(arr, row, column); for(int i=0; i<row; i++) { for(int j=0; j<column; j++) { cout << arr[i][j] << " "; } cout << endl; } return 0; } void getInput(int ** arr, int row, int column) { int inputValue =-1; int start_i = 0, start_j = 0; int last_i = row-1, last_j = column-1; int finalValue = (row*column)-1; while(inputValue!=finalValue){ for(int j=start_j; j<=last_j; j++) { inputValue+=1; arr[start_i][j] = inputValue; } if(inputValue==finalValue) break; for(int i=start_i+1; i<=last_i; i++) { inputValue+=1; arr[i][last_j] = inputValue; } if(inputValue==finalValue) break; for(int j=last_j-1; j>=start_j; j--) { inputValue+=1; arr[last_i][j] = inputValue; } if(inputValue==finalValue) break; for(int i=last_i-1; i>=start_i+1; i--) { inputValue+=1; arr[i][start_j] = inputValue; cout << "(" << i << "," << start_j << ")" << "/ InputValue = " << inputValue << endl; } if(inputValue==finalValue) break; start_i+=1; start_j+=1; last_i-=1; last_j-=1; } } ```
3 1116개 문자 삭제

2015/10/07 20:33

서영주

2 1352개 문자 추가

2015/10/07 20:31

서영주

1 Original

2015/10/07 19:36

서영주

코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.