β Birthday Gift (Contest)
Birthday Gift (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[][]=new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=sc.nextInt();
}
}
String str=sc.next();
for(int k=0;k<str.length();k++){
char ch=str.charAt(k);
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
int temp=arr[i][j];
arr[i][j]=arr[j][i];
arr[j][i]=temp;
}
}
if(ch=='R'){
for(int i=0;i<n;i++){
int low=0;
int high=n-1;
while(low<high){
int temp=arr[i][low];
arr[i][low]=arr[i][high];
arr[i][high]=temp;
low++;
high--;
}
}
}
if(ch=='L'){
for(int i=0;i<n;i++){
int low=0;
int high=n-1;
while(low<high){
int temp=arr[low][i];
arr[low][i]=arr[high][i];
arr[high][i]=temp;
low++;
high--;
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(arr[i][j]+" ");
}
if(i==n-1) break;
System.out.println();
}
}
}Last updated