(SPOJ) 10868 - Chuva - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int dimensao = Integer.valueOf(tokenizer.nextToken());
int[][] matriz = new int[dimensao][dimensao];
for (int i = 0; i < dimensao; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < dimensao; j++) {
matriz[i][j] = Integer.valueOf(tokenizer.nextToken());
}
}
for (int i = 0; i < dimensao; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < dimensao; j++) {
matriz[i][j] += Integer.valueOf(tokenizer.nextToken());
}
}
for (int i = 0; i < dimensao; i++) {
for (int j = 0; j < dimensao; j++) {
if (j == dimensao-1) {
System.out.print(matriz[i][j]);
}
else {
System.out.print(matriz[i][j] + " ");
}
}
System.out.println();
}
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = br.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int dimensao = Integer.valueOf(tokenizer.nextToken());
int[][] matriz = new int[dimensao][dimensao];
for (int i = 0; i < dimensao; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < dimensao; j++) {
matriz[i][j] = Integer.valueOf(tokenizer.nextToken());
}
}
for (int i = 0; i < dimensao; i++) {
line = br.readLine();
tokenizer = new StringTokenizer(line);
for (int j = 0; j < dimensao; j++) {
matriz[i][j] += Integer.valueOf(tokenizer.nextToken());
}
}
for (int i = 0; i < dimensao; i++) {
for (int j = 0; j < dimensao; j++) {
if (j == dimensao-1) {
System.out.print(matriz[i][j]);
}
else {
System.out.print(matriz[i][j] + " ");
}
}
System.out.println();
}
return;
}
}
Comments
Post a Comment