Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int initial[105][105];
- int arr[105][105];
- int main(){
- int row, col;
- int flag = 1;
- scanf("%d %d", &row, &col);
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++){
- scanf("%d", &initial[i][j]);
- }
- }
- int rotate;
- scanf("%d", &rotate);
- rotate = rotate % 4; //because the 4th rotate will always be back to the original array
- if( rotate == 0) {
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++){
- arr[i][j] = initial[i][j];
- }
- }
- flag = 0;
- } else if(rotate == 1){
- for(int i = 0; i < col; i++){
- for(int j = 0; j < row; j++){
- arr[i][j] = initial[row - 1 - j][i];
- }
- }
- flag = 1;
- } else if(rotate == 2){
- for(int i = 0 ; i < row; i++){
- for(int j = 0; j < col; j++){
- arr[i][j] = initial[row - 1 - i][col -1 - j];
- }
- }
- flag = 0;
- } else if(rotate == 3){
- for(int i = 0; i < col; i++){
- for(int j = 0; j < row; j++){
- arr[i][j] = initial[j][col - 1 - i];
- }
- }
- flag = 1;
- }
- // swap row and col when flag is 1
- // because I switched the row and col during the initialization process when flag is 1
- // will overprint if I don't
- if(flag == 1){
- int temp = row;
- row = col;
- col = temp;
- }
- // printing
- for(int i = 0; i < row; i++){
- for(int j = 0 ; j < col; j++){
- if(j != col - 1){
- printf("%d ", arr[i][j]);
- } else {
- printf("%d\n", arr[i][j]);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement