01-25 15:41
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ์ •๋ ฌ 10989 :: ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ 3 JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ์ •๋ ฌ 10989 :: ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ 3 JAVA

miinsun 2022. 3. 14. 15:34

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

N๊ฐœ์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— ์ˆ˜์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 10,000,000)์ด ์ฃผ์–ด์ง„๋‹ค.
  • ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
  • ์ด ์ˆ˜๋Š” 10,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค.

 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ๊ฒฐ๊ณผ๋ฅผ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

10
5
2
3
1
4
2
3
5
1
7

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

1
1
2
2
3
3
4
5
5
7

 

โ€‹

๐Ÿ’ป  Main.java

  • ์ž…์ถœ๋ ฅ ํšจ์œจ์„ ์œ„ํ•ด Scanner๋ง๊ณ  BufferdReader๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ค‘ ๊ฐ€์žฅ ํšจ์œจ์ด ์ข‹์€ ์นด์šดํŒ… ์ •๋ ฌO(n)์„ ์ด์šฉํ•ด ํ’€์ด
/* ๋ฐฑ์ค€ ์ •๋ ฌ - 10989 :: ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ - 3 */
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine());
		int [] cnt = new int [10001];
		
		for(int i = 0; i < n; i++) {
			cnt[Integer.parseInt(br.readLine())]++;
		}
		
		br.close();
		
		for(int i = 1; i < 10001; i++) {
			while(cnt[i] > 0) {
				sb.append(i).append("\n");
				cnt[i]--;
			}
		}
		
		System.out.println(sb);
		
	}
}

 

Comments