본문 바로가기

IT/알고리즘

백준 7단계(2675)

반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
public class Main {
 
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        //몇개의 수를 입력받을지 결정하는 변수
        int n = Integer.parseInt(br.readLine());
        
        //n의 개수 만큼 반복
        for(int i = 0; i < n; i++) {
            //enter할때까지 string으로 입력받기
            String str = br.readLine();
            //stringtokenizer로 입력 받은 숫자와 string구분
            StringTokenizer st = new StringTokenizer(str);
            while(st.hasMoreTokens()) {
                //숫자는 repeat
                int repeat = Integer.parseInt(st.nextToken());
                //문자열은 repeatString
                String repeatString = st.nextToken();
                //문자열의 길이만큼 첫포문 실행
                for(int j = 0; j < repeatString.length(); j++) {
                    //repeatString j의 위치에 있는 캐릭터를 repeat만큼 반복
                    for(int u = 0; u < repeat; u++) {
                        bw.write(String.valueOf(repeatString.charAt(j)));
                    }
                }
            }
            bw.write("\n");
            //n이 2를 입력 받았으면, 한번 실행 후 다시 돌기. bufferedreader의 특성 flush하기 전까지 출력이 안돼서 
            //따로 입력 받은 값와 반복한 출력 값을 저장 안해도 된다
        }
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
반응형

'IT > 알고리즘' 카테고리의 다른 글

백준 7단계(1152)  (0) 2019.12.10
백준 7단계(1157)  (0) 2019.12.10
백준 7단계(10809)  (0) 2019.12.07
백준 7단계(11720)  (0) 2019.12.07
백준 7단계(11654)  (0) 2019.12.07