fork download
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6.  
  7.  
  8. class Main
  9. {
  10. static void STAR(char[][] S, int I, int J, int K, int N)
  11. {
  12. if (N == 1) return;
  13.  
  14. S[I][J] = '*';
  15. S[I][K] = '*';
  16.  
  17. STAR(S, I + 1, J - 1, K + 1, N - 1);
  18. }
  19.  
  20. public static void main(String[] args) throws NumberFormatException, IOException
  21. {
  22.  
  23. int N = Integer.parseInt(br.readLine());
  24.  
  25. if (N == 1) { bw.write("*"); bw.flush(); return; }
  26.  
  27. char[][] S = new char[N + 1][N * 2];
  28.  
  29. S[1][N] = '*';
  30.  
  31. STAR(S, 2, N - 1, N + 1, N);
  32.  
  33. for (int i = 1; i <= N; i++)
  34. {
  35. int cnt = 2;
  36. for (int j = 1; j < N * 2; j++)
  37. {
  38. bw.write(S[i][j]);
  39. if (S[i][j] == '*') cnt--;
  40. if (i == 1 && cnt == 1) break;
  41. if (i != 1 && cnt == 0) break;
  42. }
  43. if (i != N) bw.newLine();
  44. }
  45.  
  46. bw.flush();
  47. }
  48. }
Success #stdin #stdout 0.04s 2184192KB
stdin
2
stdout
*
**