1523 : 별삼각형1
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n, m;
n = Integer.parseInt(st.nextToken());
if (n > 101) {
bw.write("INPUT ERROR!");
bw.flush();
return;
}
m = Integer.parseInt(st.nextToken());
if (m < 1 || m > 3) {
bw.write("INPUT ERROR!");
bw.flush();
return;
}
int i, j;
if (m == 1) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 2) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n - i + 1; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 3) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n - i; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= 2 * i - 1; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
}
크기와 타입을 입력받아 출력하면 되는 문제.
1719 : 별삼각형2
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n, m;
n = Integer.parseInt(st.nextToken());
if (n > 100 || n % 2 == 0) {
bw.write("INPUT ERROR!");
bw.flush();
return;
}
m = Integer.parseInt(st.nextToken());
if (m < 1 || m > 4) {
bw.write("INPUT ERROR!");
bw.flush();
return;
}
int i, j;
if (m == 1) {
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
for (i = 1; i <= n/2; i++) {
for (j = 1; j <= (n / 2 + 1) - i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 2) {
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= (n / 2 + 1) - i; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
for (i = 1; i <= n / 2; i++) {
for (j = 1; j <= i; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= (n / 2 + 1) - i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 3) {
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= i - 1; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= n + 2 - (i * 2); j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
for (i = 1; i <= n / 2; i++) {
for (j = 1; j <= n / 2 - i; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= 2 * i + 1; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 4) {
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= i - 1; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= n / 2 + 2 - i; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
for (i = 1; i <= n / 2; i++) {
for (j = 1; j <= n / 2; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= i + 1; j++) {
bw.write("*");
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
}
마찬가지로 크기와 타입을 입력받아 출력하면 되는 문제.
1329 : 별삼각형3
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n;
n = Integer.parseInt(st.nextToken());
if (n > 101 || n < 1 || n % 2 == 0) {
bw.write(String.format("INPUT ERROR!"));
bw.flush();
return;
}
int i, j;
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= i - 1; j++) {
bw.write((" "));
bw.flush();
}
for (j = 1; j <= i * 2 - 1; j++) {
bw.write(("*"));
bw.flush();
}
bw.write(("\n"));
bw.flush();
}
for (i = 1; i <= n / 2; i++) {
for (j = 1; j <= n / 2 - i; j++) {
bw.write((" "));
bw.flush();
}
for (j = 1; j <= n - i * 2; j++) {
bw.write(("*"));
bw.flush();
}
bw.write(("\n"));
bw.flush();
}
}
}
크기를 입력받아 출력하면 되는 문제.
1641 : 숫자삼각형
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n, m;
n = Integer.parseInt(st.nextToken());
if (n > 100 || n % 2 == 0) {
bw.write(("INPUT ERROR!"));
bw.flush();
return;
}
m = Integer.parseInt(st.nextToken());
if (m < 1 || m > 3) {
bw.write(("INPUT ERROR!"));
bw.flush();
return;
}
int i, j;
int arr[][] = new int [101][101];
int cnt = 1;
if (m == 1) {
for (i = 1; i <= n; i++) {
if (i % 2 != 0) {
for (j = 1; j <= i; j++) {
arr[i][j] = cnt++;
}
}
else {
for (j = i; j >= 1; j--) {
arr[i][j] = cnt++;
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
bw.write(String.format("%d ", arr[i][j]));
}
bw.write("\n");
bw.flush();
}
}
else if (m == 2) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= i - 1; j++) {
bw.write(" ");
bw.flush();
}
for (j = 1; j <= (2*n-1) - i * 2 + 2; j++) {
bw.write(String.format("%d ", i - 1));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 3) {
for (i = 1; i <= n / 2 + 1; i++) {
for (j = 1; j <= i; j++) {
bw.write(String.format("%d ", j));
bw.flush();
}
bw.write(("\n"));
bw.flush();
}
for (i = 1; i <= n / 2; i++) {
for (j = 1; j <= n / 2 - i + 1; j++) {
bw.write(String.format("%d ", j));
bw.flush();
}
bw.write(("\n"));
bw.flush();
}
}
}
}
크기와 타입을 입력받아 숫자로 출력하면 되는 문제.
1707 : 달팽이사각형
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n;
n = Integer.parseInt(st.nextToken());
int i, j;
int arr[][] = new int [101][101];
int cnt = 0;
for (i = 0; i <= n+1; i++) {
arr[i][0] = 1;
arr[0][i] = 1;
arr[i][n+1] = 1;
arr[n+1][i] = 1;
}
int x,y;
x=y=1;
int dir=0;
int num=1;
for (i = 1; i <= n * n; i++) {
arr[y][x] = num++;
if (dir == 0) {
if (arr[y][x + 1] == 0) x++;
else {
dir = 1;
y++;
}
}
else if (dir == 1) {
if (arr[y + 1][x] == 0) y++;
else {
dir = 2;
x--;
}
}
else if (dir == 2) {
if (arr[y][x - 1] == 0) x--;
else {
dir = 3;
y--;
}
}
else {
if (arr[y - 1][x] == 0) y--;
else {
dir = 0;
x++;
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
크기를 입력받아 사각형 달팽이 모양으로 숫자를 출력하면 되는 문제.
1337 : 달팽이삼각형
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n;
int arr[][] = new int [101][101];
int i, j;
int x=0, y=0;
int cnt = 0;
n = Integer.parseInt(st.nextToken());
for (i = n - 1; i > 0; i -= 3) {
for (j = 1; j <= i; j++) {
if (cnt > 9) cnt = 0;
arr[y++][x++] = cnt++;
}
for (j = 1; j <= i; j++) {
if (cnt > 9) cnt = 0;
arr[y][x--] = cnt++;
}
for (j = 1; j <= i; j++) {
if (cnt > 9) cnt = 0;
arr[y--][x] = cnt++;
}
y+=2;
x++;
}
if(i==0) {
if (cnt > 9) cnt = 0;
arr[y][x] = cnt;
}
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
bw.write(String.format("%d ", arr[i][j]));;
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
크기를 입력받아 삼각형 달팽이 모양으로 숫자를 출력하면 되는 문제.
2071 : 파스칼 삼각형
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n, m;
int arr[][] = new int [101][101];
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int i, j;
if (m == 1) {
arr[0][1] = 1;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
else if (m == 2) {
arr[n][n] = 1;
for (i = n - 1; i > 0; i--) {
for (j = 1; j < n * 2; j++) {
arr[i][j] = arr[i + 1][j] + arr[i + 1][j + 1];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j < n * 2; j++) {
if (arr[i][j] == 0) {
bw.write(" ");
bw.flush();
}
else {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
}
bw.write("\n");
bw.flush();
}
}
else if (m == 3) {
arr[n][n] = 1;
for (i = n-1; i >0; i--) {
for (j = n; j >= 0; j--) {
arr[j][i] = arr[j][i+1] + arr[j + 1][i + 1];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
}
크기와 타입을 입력받아 파스칼 삼각형 모양으로 출력하면 되는 문제.
1331 : 문자마름모
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int i, j;
int n;
n = Integer.parseInt(st.nextToken());
int x = n, y = 1;
char arr[][] = new char [201][201];
char alpha = 'A';
for (i = n - 1; i > 0; i--) {
for (j = 1; j <= i; j++) {
if (alpha > 'Z') alpha = 'A';
arr[y++][x--] = alpha++;
}
for (j = 1; j <= i; j++) {
if (alpha > 'Z') alpha = 'A';
arr[y++][x++] = alpha++;
}
for (j = 1; j <= i; j++) {
if (alpha > 'Z') alpha = 'A';
arr[y--][x++] = alpha++;
}
for (j = 1; j <= i; j++) {
if (alpha > 'Z') alpha = 'A';
arr[y--][x--] = alpha++;
}
y++;
}
if (alpha > 'Z') alpha = 'A';
arr[y][x] = alpha++;
for (i = 1; i <= n * 2 - 1; i++) {
for (j = 1; j <= n * 2 - 1; j++) {
if (arr[i][j] == 0) {
bw.write(" ");
}
else {
bw.write(String.format("%c ", arr[i][j]));
}
}
bw.write("\n");
bw.flush();
}
}
}
크기를 입력받아 마름모 모양을 역시계방향으로 출력하면 되는 문제.
1495 : 대각선 지그재그
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int i, j;
int n;
int x, y;
int arr[][] = new int[110][110];
n = Integer.parseInt(st.nextToken());
y=x=1;
int dir=0;
int num=1;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
if (dir == 0) {
arr[y++][x--] = num++;
}
else {
arr[y--][x++] = num++;
}
}
if (dir == 0) {
x++;
}
else {
y++;
}
dir=1-dir;
}
if(dir==0) {
y++;
x--;
}
else {
y--;
x++;
}
for (i = n - 1; i >= 0; i--) {
for (j = 1; j <= i; j++) {
if (dir == 0) {
arr[y++][x--] = num++;
}
else {
arr[y--][x++] = num++;
}
}
if (dir == 0) {
x+=2;
y--;
}
else {
y+=2;
x--;
}
dir=1-dir;
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
크기를 입력받아 지그재그 모양으로 숫자를 출력하면 되는 문제.
2074 : 홀수 마방진
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int arr[][] = new int [101][101];
int n;
int i, j;
n = Integer.parseInt(st.nextToken());
int y,x;
int num = 1;
x = n / 2;
y = 0;
for (i = 1; i <= n * n; i++) {
arr[y][x] = num++;
if (arr[(y-1 + n) % n][(x-1 + n) % n] != 0) {
y=(y+1)%n;
}
else {
y= (y-1 + n) % n;
x=(x-1 + n) % n;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
bw.write(String.format("%d ", arr[i][j]));
bw.flush();
}
bw.write("\n");
bw.flush();
}
}
}
크기를 입력받아 마방진 모양으로 숫자를 출력하면 되는 문제.