problem id:--https://www.hackerrank.com/challenges/flipping-the-matrix
code:--
// c++ code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii std::pair<int,int>
#define vi std::vector<int>
#define vll std::vector<long long>
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x)
#define pf2(x,y) printf("%d %d ",x,y)
#define pf3(x,y,z) printf("%d %d %d ",x,y,z)
#define pfnl() putchar('\n');
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep2(i,j,n) for(int i = j; i < (n); ++i)
#define fill(a) memset(a, 0, sizeof (a))
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define X first
#define Y second
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define MOD 1000000007
int main(int argc, char **argv) {
//std::ios::sync_with_stdio(false);
int arr[260][260];
int q;
sc(q);
int n;
while(q--)
{
sc(n);
rep(i,2*n) rep(j,2*n) sc(arr[i][j]);
int ans=0;
rep(i,n) rep(j,n) ans+=max(arr[2*n-i-1][2*n-j-1],max(arr[i][j],max(arr[i][2*n-j-1],arr[2*n-i-1][j])));
pf(ans);
pfnl();
}
return 0;
}
//java code:-
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int[][] arr=new int[260][260];
int q=sc.nextInt();
int n;
while(q-- >0)
{
n=sc.nextInt();
for(int i=0;i<2*n;++i)
{
for(int j=0;j<2*n;++j)
{
arr[i][j]=sc.nextInt();
}
}
int ans=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
ans+=Math.max(Math.max(arr[i][j],arr[2*n-i-1][j]),Math.max(arr[i][2*n-j-1],arr[2*n-i-1][2*n-j-1]));
}
}
System.out.println(ans);
}
}
}
code:--
// c++ code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii std::pair<int,int>
#define vi std::vector<int>
#define vll std::vector<long long>
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x)
#define pf2(x,y) printf("%d %d ",x,y)
#define pf3(x,y,z) printf("%d %d %d ",x,y,z)
#define pfnl() putchar('\n');
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep2(i,j,n) for(int i = j; i < (n); ++i)
#define fill(a) memset(a, 0, sizeof (a))
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define X first
#define Y second
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define MOD 1000000007
int main(int argc, char **argv) {
//std::ios::sync_with_stdio(false);
int arr[260][260];
int q;
sc(q);
int n;
while(q--)
{
sc(n);
rep(i,2*n) rep(j,2*n) sc(arr[i][j]);
int ans=0;
rep(i,n) rep(j,n) ans+=max(arr[2*n-i-1][2*n-j-1],max(arr[i][j],max(arr[i][2*n-j-1],arr[2*n-i-1][j])));
pf(ans);
pfnl();
}
return 0;
}
//java code:-
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int[][] arr=new int[260][260];
int q=sc.nextInt();
int n;
while(q-- >0)
{
n=sc.nextInt();
for(int i=0;i<2*n;++i)
{
for(int j=0;j<2*n;++j)
{
arr[i][j]=sc.nextInt();
}
}
int ans=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
ans+=Math.max(Math.max(arr[i][j],arr[2*n-i-1][j]),Math.max(arr[i][2*n-j-1],arr[2*n-i-1][2*n-j-1]));
}
}
System.out.println(ans);
}
}
}
No comments:
Post a Comment