View

๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/2870

 

2870๋ฒˆ: ์ˆ˜ํ•™์ˆ™์ œ

์ข…์ด์—์„œ ์ฐพ์€ ์ˆซ์ž์˜ ๊ฐœ์ˆ˜๋ฅผ M์ด๋ผ๊ณ  ํ•˜๋ฉด, ์ถœ๋ ฅ์€ M์ค„๋กœ ์ด๋ฃจ์–ด์ ธ์•ผ ํ•œ๋‹ค. ๊ฐ ์ค„์—๋Š” ์ข…์ด์—์„œ ์ฐพ์€ ์ˆซ์ž๋ฅผ ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ด๋•Œ, ๋น„๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ๋น„๋‚ด๋ฆผ์ฐจ์ˆœ์€ ๋‚ด๋ฆผ์ฐจ

www.acmicpc.net

 

package ๋ฌธ์ž์—ด;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;

public class Main_2078 {
	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		ArrayList<BigInteger> arr = new ArrayList<>();// ๋ฒ”์œ„ ๋•Œ๋ฌธ์— BigInteger๋ฅผ ์„ ์–ธ

		for (int i = 0; i < T; i++) {
			String[] s = br.readLine().split("\\D"); // ์ˆซ์ž๋งŒ ๋‚จ๊ธฐ๊ณ  ๋‹ค ์ž๋ฆ„ (๊ทธ๋Ÿฌ๋‚˜ ๋ฌธ์ž๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๋˜์–ด์žˆ๊ธฐ์— ์ œ๊ฑฐ ํ•„์ˆ˜ )
			for (int j = 0; j < s.length; j++) {
				if (!s[j].equals("")) {
					arr.add(new BigInteger(s[j]));
				}
				;
			}
			arr.sort(null);// null => ๋น„๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ
		}

		for (int i = 0; i < arr.size(); i++) {
			System.out.println(arr.get(i));
		}
	}
}

 

 

๐Ÿ’ก Int, long ๋ณด๋‹ค ํฐ ์ •์ˆ˜ํƒ€์ž… : BigInteger์„ ์‚ฌ์šฉ 

 

๐Ÿ’ก ์ˆซ์ž๋งŒ ๋‚จ๊ธฐ๊ณ  ๋‹ค ์ž๋ฆ„  (split ์‚ฌ์šฉ -> ์ฐธ๊ณ  ๋งํฌ )

String[] s = br.readLine().split("\\D"); // ์ˆซ์ž๋งŒ ๋‚จ๊ธฐ๊ณ  ๋‹ค ์ž๋ฆ„ (๊ทธ๋Ÿฌ๋‚˜ ๋ฌธ์ž๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๋˜์–ด์žˆ๊ธฐ์— ์ œ๊ฑฐ ํ•„์ˆ˜ )

https://jamesdreaming.tistory.com/84

 

[ ์ž๋ฐ” ์ฝ”๋”ฉ ] Java split() ํ•จ์ˆ˜๋กœ ๋ฌธ์ž์—ด ์ž๋ฅด๊ธฐ

์•ˆ๋…•ํ•˜์„ธ์š”. ์ œ์ž„์Šค ์ž…๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” Java ์—์„œ String ์„ ๋‹ค๋ฃฐ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜ ์ค‘ ํ•œ๊ฐ€์ง€์ธ split ํ•จ์ˆ˜์— ๋Œ€ํ•ด ์•Œ์•„ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. โ–  String[] split(String regex) split ํ•จ์ˆ˜๋Š” ์ž…๋ ฅ๋ฐ›์€ ์ •

jamesdreaming.tistory.com

 

๋ฐ˜์‘ํ˜•
Share Link
reply
๋ฐ˜์‘ํ˜•
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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