Task: | Fraktaali |
Sender: | RoniTuohino |
Submission time: | 2017-10-04 15:42:30 +0300 |
Language: | Java |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 10 |
#3 | ACCEPTED | 10 |
#4 | ACCEPTED | 10 |
#5 | ACCEPTED | 10 |
#6 | ACCEPTED | 10 |
#7 | ACCEPTED | 10 |
#8 | ACCEPTED | 10 |
#9 | ACCEPTED | 10 |
#10 | ACCEPTED | 10 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.14 s | 1 | details |
#2 | ACCEPTED | 0.16 s | 2 | details |
#3 | ACCEPTED | 0.16 s | 3 | details |
#4 | ACCEPTED | 0.16 s | 4 | details |
#5 | ACCEPTED | 0.18 s | 5 | details |
#6 | ACCEPTED | 0.19 s | 6 | details |
#7 | ACCEPTED | 0.21 s | 7 | details |
#8 | ACCEPTED | 0.24 s | 8 | details |
#9 | ACCEPTED | 0.35 s | 9 | details |
#10 | ACCEPTED | 0.53 s | 10 | details |
Code
import java.util.*;public class Main {public static void main(String[] args) {Scanner s = new Scanner(System.in);int f = s.nextInt();int size = (int)CalculateSize(f);char[][]startFrac = new char[size][size];for (int x = 0; x < startFrac.length; x++){ //Turn all spaces black '#'for (int y = 0; y < startFrac.length; y++){startFrac[x][y] = '#';}}startFrac = BuildFractal(startFrac, size, f);PrintFractal(startFrac);}public static double CalculateSize(double x){ //Calculate the size for the fractalif(x == 1){x = 1;} else if(x == 2){x = 2;} else if(x == 3){x = 4;} else if(x == 4){x = 8;} else if(x >= 5){x = Math.pow(2, x-1);}return x;}public static char[][] BuildFractal(char[][] frac, int size, int f){ //Build the final fractalchar[][] finalFrac;finalFrac = frac;if(f == 1){return finalFrac;}finalFrac[1][1] = '.'; //First white piece on the cornerif(f == 2){return finalFrac;}for(int i = 2; i < f; i++){ //Do this loop until fractal is complete//Insert all the corners of the fractalfinalFrac = SetTheCorners(finalFrac, (int)CalculateSize(i+1) ,(int)CalculateSize(i));}return finalFrac;}public static char[][] SetTheCorners(char[][] frac, int size, int pos){ //Set the on the fractalchar[][] finalFrac = frac;char[][] copy = new char[pos][pos];//System.out.println(pos);for(int x = 0; x < pos; x++){ //Copy is now the corner to setfor(int y = 0; y < pos; y++){copy[x][y] = finalFrac[x][y];}}for(int x = 0; x <= pos - 1; x++){ //Set the first corner on the top rightfor(int y = pos; y <= size - 1; y++){if(copy[x][y - pos] == '.'){finalFrac[x][y] = '.';}}}for(int x = pos; x <= size - 1; x++){ //Set the second corner on the bottom leftfor(int y = 0; y <= pos - 1; y++){if(copy[x - pos][y] == '.'){finalFrac[x][y] = '.';}}}for(int x = pos; x <= size - 1; x++){ //Scans the bottom right negativefor(int y = pos; y <= size - 1; y++){//finalFrac[x][y] = '.';if(copy[x - pos][y - pos] == '#'){finalFrac[x][y] = '.';}else if(copy[x - pos][y - pos] == '.'){finalFrac[x][y] = '#';}}}return finalFrac;}public static void PrintFractal(char[][] frac){ //Print the fractalfor (int x = 0; x < frac.length; x++){System.out.println("");for(int y=0; y < frac.length; y++){System.out.print(frac[x][y]);}}}}
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
# |
user output |
---|
# |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
## #. |
user output |
---|
## #. |
Test 3
Group: 3
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
#### #.#. ##.. #..# |
user output |
---|
#### #.#. ##.. #..# |
Test 4
Group: 4
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
######## #.#.#.#. ##..##.. #..##..# ####.... ... |
user output |
---|
######## #.#.#.#. ##..##.. #..##..# ... |
Test 5
Group: 5
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
################ #.#.#.#.#.#.#.#. ##..##..##..##.. #..##..##..##..# ####....####.... ... |
user output |
---|
################ #.#.#.#.#.#.#.#. ##..##..##..##.. #..##..##..##..# ... |
Test 6
Group: 6
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
##############################... |
user output |
---|
##############################... |
Test 7
Group: 7
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
##############################... |
user output |
---|
##############################... |
Test 8
Group: 8
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
##############################... |
user output |
---|
##############################... |
Test 9
Group: 9
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
##############################... |
user output |
---|
##############################... |
Test 10
Group: 10
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
##############################... |
user output |
---|
##############################... |