200916 수 [BOJ] 2445, 2522, 2446, 10991, 10992
BOJ 2445
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
for(int i=0;i<N;i++) {
for(int j=0;j<2*N;j++) {
if(j>i && j<(2*N) - (i+1)) {
bw.write(' ');
} else {
bw.write('*');
}
}
bw.newLine();
}
for(int i=0;i<N-1;i++) {
for(int j=0;j<2*N;j++) {
if(j>=N-(i+1) && j<=N+i) {
bw.write(' ');
} else {
bw.write('*');
}
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
BOJ 2522
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
for(int i=0;i<N;i++) {
for(int j=0;j<N;j++) {
if(j<N-i-1) {
bw.write(' ');
} else {
bw.write('*');
}
}
bw.newLine();
}
for(int i=0;i<N-1;i++) {
for(int j=0;j<N;j++) {
if(j<i+1) {
bw.write(' ');
} else {
bw.write('*');
}
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
별찍기 슬슬 귀찮...🤔
BOJ 2446
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
for(int i=0;i<N;i++) {
for(int j=0;j<(2*N)-1;j++) {
if(j<i) {
bw.write(' ');
} else if (j<=(2*N)-i-2){
bw.write('*');
}
}
bw.newLine();
}
for(int i=0;i<N-1;i++) {
for(int j=0;j<(2*N)-1;j++) {
if(j<N-i-2) {
bw.write(' ');
} else if (j<=N+i){
bw.write('*');
}
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
*
뒤에 공백이 있을 때는 '출력 형식이 잘못되었습니다'로 나옴. 공백 제거하니 정답.
BOJ 10991
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
br.close();
for(int i=0;i<N;i++) {
for(int j=0;j<N-i-1;j++) {
bw.write(' ');
}
for(int k=0;k<i+1;k++) {
bw.write("* ");
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
별찍기 문제기인한데 약간 독특했다. 앞에 공백을 먼저 다 찍어두고 시작!
슬슬 별찍기가 지겨워진다...😫 이제 I/O 한 문제 남았다!!
BOJ 10992
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
br.close();
for(int i=0;i<N;i++) {
if(i==N-1) {
for(int j=0;j<(2*N)-1;j++) {
bw.write('*');
}
} else {
for(int j=0;j<N-i-1;j++) {
bw.write(' ');
}
for(int k=0;k<2*(i+1)-1;k++) {
if(k==0) {
bw.write('*');
} else if (k==2*(i+1)-2) {
bw.write('*');
} else {
bw.write(' ');
}
}
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
Author And Source
이 문제에 관하여(200916 수 [BOJ] 2445, 2522, 2446, 10991, 10992), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kyuhyunhan/200916-수-BOJ-2445-2522-2446-10991저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)