pages:
- 1
N@R!MAN SAYS
I've tried many ways But still get Presentation Error!:(
#include <iostream>
#define max 60
using namespace std;
int board[max][max];
void upward(int);
void downward(int);
void forward(int);
void backward(int);
void transpose(int);
void rotate(int);
int main()
{
int t, n, i, j, notfirst = 0;
char str[100];
cin >> t;
while(t--)
{
if(notfirst)
{
cout << endl;
}
cin >> n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin >> board[i][j];
}
}
cin >> str;
for(i=0;str[i];i++)
{
switch(str[i])
{
case 'U':
upward(n);
break;
case 'D':
downward(n);
break;
case 'F':
forward(n);
break;
case 'B':
backward(n);
break;
case 'T':
transpose(n);
break;
case 'R':
rotate(n);
break;
};
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout << board[i][j];
if(j != n-1)
{
cout << " ";
}
}
cout << endl;
}
notfirst = 1;
}
return 0;
}
void upward(int n)
{
int temp[max], i, j;
for(i=0;i<n;i++)
{
temp[i] = board[0][i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
board[i][j] = board[i+1][j];
}
}
for(i=0;i<n;i++)
{
board[n-1][i] = temp[i];
}
}
void downward(int n)
{
int temp[max], i, j;
for(i=0;i<n;i++)
{
temp[i] = board[n-1][i];
}
for(i=n-2;i>=0;i--)
{
for(j=0;j<n;j++)
{
board[i+1][j] = board[i][j];
}
}
for(i=0;i<n;i++)
{
board[0][i] = temp[i];
}
}
void forward(int n)
{
int temp[max], i, j;
for(i=0;i<n;i++)
{
temp[i] = board[i][n-1];
}
for(j=n-2;j>=0;j--)
{
for(i=0;i<n;i++)
{
board[i][j+1] = board[i][j];
}
}
for(i=0;i<n;i++)
{
board[i][0] = temp[i];
}
}
void backward(int n)
{
int temp[max], i, j;
for(i=0;i<n;i++)
{
temp[i] = board[i][0];
}
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
board[i][j] = board[i][j+1];
}
}
for(i=0;i<n;i++)
{
board[i][n-1] = temp[i];
}
}
void transpose(int n)
{
int i, j, temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
temp = board[i][j];
board[i][j] = board[j][i];
board[j][i] = temp;
}
}
}
void rotate(int n)
{
int i, j, k, temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
temp = board[i][j];
board[i][j] = board[j][i];
board[j][i] = temp;
}
}
for(i=0;i<n;i++)
{
for(j=0,k=n-1;j<k;j++,k--)
{
temp = board[i][j];
board[i][j] = board[i][k];
board[i][k] = temp;
}
}
}
AMiR SAYS
The last line of output section says
You should print an empty line after each test.
There is no need to check if this is the first testcase or not. You have to print a blank line after each testcase!
You can remove the these lines:
if(notfirst)
{
cout << endl;
}
and in the last lines of main
function (that prints the board
array), instead of notfirst = 1;
just print another blank line: cout << endl;
N@R!MAN SAYS
Tnx So Much!
Login please!
In order to post something you must login first. You can use the form in the top of this page.