| Task: | Ruudukko |
| Sender: | matskuman5 |
| Submission time: | 2019-10-09 19:43:20 +0300 |
| Language: | C++ (C++11) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp:6:14: error: stray '\344' in program
package datatähti;
^
input/code.cpp:13:19: error: stray '\344' in program
public class Datatähti {
^
input/code.cpp:6:1: error: 'package' does not name a type
package datatähti;
^~~~~~~
input/code.cpp:7:1: error: 'import' does not name a type; did you mean 'short'?
import java.util.Scanner;
^~~~~~
short
input/code.cpp:13:1: error: expected unqualified-id before 'public'
public class Datatähti {
^~~~~~Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package datatähti;
import java.util.Scanner;
/**
*
* @author Matias
*/
public class Datatähti {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner lukija = new Scanner(System.in);
int n = Integer.valueOf(lukija.nextLine());
int[][] ruudukko = new int[n][n];
int lisattavaNumero = 1;
for (int rivi = 0; rivi < n; rivi++) {
for (int sarake = 0; sarake < n; sarake++) {
if (rivi == 0 && sarake == 0) {
ruudukko[rivi][0] = 1;
continue;
}
while (true) {
boolean reset = false;
for (int s = 0; s < sarake; s++) {
if (lisattavaNumero == ruudukko[rivi][s]) {
reset = true;
}
}
if (rivi > 0) {
for (int r = 0; r < rivi; r++) {
if (lisattavaNumero == ruudukko[r][sarake]) {
reset = true;
}
}
}
if (reset) {
lisattavaNumero++;
continue;
} else {
break;
}
}
ruudukko[rivi][sarake] = lisattavaNumero++;
lisattavaNumero = 1;
}
}
StringBuilder rakentaja;
for (int rivi = 0; rivi < n; rivi++) {
rakentaja = new StringBuilder();
for (int sarake = 0; sarake < n; sarake++) {
rakentaja.append(ruudukko[rivi][sarake]);
rakentaja.append(" ");
}
System.out.println(rakentaja.toString());
}
}
}
