๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 5648_์—ญ์›์†Œ ์ •๋ ฌ

๋ฟŒ์•ผ._. 2023. 10. 26. 12:04

Silver V

๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/5648)

< ์—ญ์›์†Œ ์ •๋ ฌ >

 

๋ฌธ์ œ ํ’€์ด 

 

์›์†Œ๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ ์›์†Œ๋ฅผ ๋’ค์ง‘์€ ํ›„ ์›์†Œ๋“ค์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

 

 

 my solution (Java)

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class _5648_ { // ์—ญ์›์†Œ ์ •๋ ฌ

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st = new StringTokenizer(bf.readLine());

		int n = Integer.parseInt(st.nextToken());

		long arr[] = new long[n];
		String str = "", temp = "";

		while (n > 0) {
			while (st.hasMoreTokens()) {
				str = st.nextToken();
				temp = "";
				for (int i = str.length() - 1; i >= 0; i--) {
					temp += str.charAt(i);
				}
				arr[--n] = Long.parseLong(temp);
			}
			if(n>0)
				st = new StringTokenizer(bf.readLine());
		}
		Arrays.sort(arr);
		for(int i=0; i<arr.length; i++) {
			bw.write(arr[i]+"\n");
		}
		bw.flush();
	}
}

 

Main

๋ณ€์ˆ˜)
n : ์›์†Œ ์ˆ˜
arr : ๋’ค์ง‘์€ ์›์†Œ ์ €์žฅ ๋ฐฐ์—ด
str : ์›์†Œ 
temp : ์›์†Œ ๋’ค์ง‘์€ ๊ฐ’

 

- ์›์†Œ ์ˆ˜(n) ์ž…๋ ฅ

- ์›์†Œ ์ˆ˜(n)๋งŒํผ ์ž…๋ ฅ๋ฐ›์Œ

: ์›์†Œ(str)๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๊ฑฐ๊พธ๋กœ ๋’ค์ง‘์€ ํ›„(temp) ๋ฐฐ์—ด์— ์ €์žฅ

- ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ ํ›„ ์ถœ๋ ฅ