01-09 18:44
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 11656 :: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 11656 :: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด JAVA

miinsun 2022. 3. 15. 20:30

 

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

์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด์€ ๋ฌธ์ž์—ด S์˜ ๋ชจ๋“  ์ ‘๋ฏธ์‚ฌ๋ฅผ ์‚ฌ์ „์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด ๋†“์€ ๋ฐฐ์—ด์ด๋‹ค.

baekjoon์˜ ์ ‘๋ฏธ์‚ฌ๋Š” baekjoon, aekjoon, ekjoon, kjoon, joon, oon, on, n ์œผ๋กœ ์ด 8๊ฐ€์ง€๊ฐ€ ์žˆ๊ณ ,
์ด๋ฅผ ์‚ฌ์ „์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋ฉด, aekjoon, baekjoon, ekjoon, joon, kjoon, n, on, oon์ด ๋œ๋‹ค.

๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ชจ๋“  ์ ‘๋ฏธ์‚ฌ๋ฅผ ์‚ฌ์ „์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ๋‹ค์Œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

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

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.
 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ S์˜ ์ ‘๋ฏธ์‚ฌ๋ฅผ ์‚ฌ์ „์ˆœ์œผ๋กœ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•œ๋‹ค.

 

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

baekjoon

 

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

aekjoon
baekjoon
ekjoon
joon
kjoon
n
on
oon

 

โ€‹

๐Ÿ’ป  Main.java

  • String.substring()์œผ๋กœ ๋ฌธ์ž์—ด์„ ์•ž์—์„œ๋ถ€ํ„ฐ ํ•œ๊ฐœ์”ฉ ๊ฐ์„œ
  •  Arrays.sort()๋กœ ๋ฌธ์ž์—ด ๋ฐฐ์—ด์„ ๋‚ด๋ฆผ์ฐจ ์ˆœ์œผ๋กœ ์ •๋ ฌ
/* ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ - 11656 :: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด */
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] arr = new String[s.length()];
		
		for(int i = 0; i < arr.length; i++) 
			arr[i] = s.substring(i);
		
		Arrays.sort(arr);
		for(String tmp : arr)
			System.out.println(tmp);
		
		sc.close();
	}
}
Comments