Created
October 8, 2013 14:43
-
-
Save joemmanuel/6885843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
using namespace std; | |
int height, width, movs, opnum, opin; | |
int ops[10], board[105][105], nboard[105][105]; | |
void adjust() | |
{ | |
for(int i=1; i<=2; i++) | |
{ | |
ops[i]=ops[i]%height; | |
} | |
for(int i=3; i<=4; i++) | |
{ | |
ops[i]=ops[i]%width; | |
} | |
if(ops[1]>ops[2]) | |
{ | |
ops[1]-=ops[2]; | |
ops[2]=0; | |
} | |
else | |
{ | |
ops[2]-=ops[1]; | |
ops[1]=0; | |
} | |
if(ops[3]>ops[4]) | |
{ | |
ops[3]-=ops[4]; | |
ops[4]=0; | |
} | |
else | |
{ | |
ops[4]-=ops[3]; | |
ops[3]=0; | |
} | |
} | |
void trans() | |
{ | |
for(int i=1; i<=height; i++) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
board[j][i]=nboard[j][i]; | |
} | |
} | |
} | |
int up(int num) | |
{ | |
while(num<=0) | |
num+=height; | |
return num; | |
} | |
int down(int num) | |
{ | |
while(num>height) | |
num-=height; | |
return num; | |
} | |
int left(int num) | |
{ | |
while(num<=0) | |
num+=width; | |
return num; | |
} | |
int right(int num) | |
{ | |
while(num>width) | |
num-=width; | |
return num; | |
} | |
int main() | |
{ | |
scanf("%d%d%d", &height, &width, &movs); | |
for(int i=1; i<=movs; i++) | |
{ | |
scanf("%d", &opin); | |
ops[opin]++; | |
} | |
for(int i=1; i<=height; i++) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
scanf("%d", &board[j][i]); | |
} | |
} | |
//UP=1, DOWN=2, LEFT=3, RIGHT=4 | |
adjust(); | |
if(ops[1]) | |
{ | |
for(int i=1; i<=height; i++) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
nboard[j][up(i-ops[1])]=board[j][i]; | |
} | |
} | |
trans(); | |
} | |
if(ops[2]) | |
{ | |
for(int i=1; i<=height; i++) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
nboard[j][down(i+ops[2])]=board[j][i]; | |
} | |
} | |
trans(); | |
} | |
if(ops[3]) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
for(int i=1; i<=height; i++) | |
{ | |
nboard[left(j-ops[3])][i]=board[j][i]; | |
} | |
} | |
trans(); | |
} | |
if(ops[4]) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
for(int i=1; i<=height; i++) | |
{ | |
nboard[right(j+ops[4])][i]=board[j][i]; | |
} | |
} | |
trans(); | |
} | |
for(int i=1; i<=height; i++) | |
{ | |
for(int j=1; j<=width; j++) | |
{ | |
printf("%d", board[j][i]); | |
if(j<width) | |
printf(" "); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment