Pagini recente » Cod sursa (job #328967) | Cod sursa (job #2542786) | Cod sursa (job #2697358) | Cod sursa (job #1831147) | Cod sursa (job #2179278)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class Main
{
public static int make_sum(int[] v)
{
int suma=0;
for(int i=0;i<v.length;i++)
suma+=v[i];
return suma;
}
public static void main(String[] args) {
Scanner keyboardScanner = new Scanner(System.in);
int[][] mat = new int[16][16];
int row;
int col;
int s;
int suma=0;
int[] rows=new int[16];
int[] cols=new int[16];
int[] temp=new int[16];
while(keyboardScanner.hasNextLine()) {
String line = keyboardScanner.nextLine();
String[] parts = line.split(" ");
row = Integer.parseInt(parts[0]);
col = Integer.parseInt(parts[1]);
for (int i=0;i<row;i++)
for(int j=0;j<col;j++)
mat[i][j]=keyboardScanner.nextInt();
for(int i=0;i<row;i++)
{ for(int j=0;j<col;j++)
{rows[j]=mat[i][j];
temp[j]=mat[i][j]*-1;}
if (make_sum(rows)<make_sum(temp))
{
for(int p=0;p<col;p++)
mat[i][p]=temp[p];
}
else
{
for(int p=0;p<col;p++)
mat[i][p]=rows[p];
}
}
for(int i=0;i<col;i++)
{ for(int j=0;j<row;j++)
{cols[j]=mat[j][i];
temp[j]=mat[j][i]*-1;}
if (make_sum(cols)<make_sum(temp))
{
for(int p=0;p<row;p++)
mat[p][i]=temp[p];
}
else
{
for(int p=0;p<row;p++)
mat[p][i]=cols[p];
}
}
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
suma+=mat[i][j];
PrintWriter writer= null;
try {
writer = new PrintWriter("flip.out");
} catch(FileNotFoundException e) {
e.printStackTrace();
}
writer.println(suma);
writer.close();
//System.out.println(suma);
}
}
}