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();
    }
}

좋은 웹페이지 즐겨찾기