Skip to content

Instantly share code, notes, and snippets.

@joemmanuel
Created October 8, 2013 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemmanuel/6885843 to your computer and use it in GitHub Desktop.
Save joemmanuel/6885843 to your computer and use it in GitHub Desktop.
#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