๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ

    [JAVA] ๋ฐฑ์ค€ 10824๋ฒˆ ใ€์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ดใ€‘

    ์ด ๋ฌธ์ œ๋Š” ๋ฌธ์ž์—ด๋กœ ์ž…๋ ฅ์„ ๋ฐ›์€ ๋’ค, substring(start index, end index) ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ, ๋งŒ๋“ค์–ด๋‘” String [] ๋ฐฐ์—ด์— ๋ฌธ์ž๋ฅผ ์ชผ๊ฐœ์„œ ์ž…๋ ฅํ•œ ๋’ค, sort๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String i..

    [JAVA] ๋ฐฑ์ค€ 10824๋ฒˆ ใ€๋„ค ์ˆ˜ใ€‘

    ์ด ๋ฌธ์ œ ์—ญ์‹œ !! ๋งค์šฐ ๊ธฐ์ดˆ์ ์ธ ๋ฌธ์ œ์ด๋‹ค. ๋‘ ์ˆ˜๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์€ ๋ฌธ์ž์—ด์˜ ์„ฑ์งˆ์„ ์ด์šฉํ•ด์„œ ํ•ฉ์น˜๋ฉด ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ๋ถ™์ธ ๊ฐ’์ด int ๋ฒ”์œ„๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, long ํƒ€์ž…์œผ๋กœ ๋ฐ›์•„์•ผ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] input = br.readLi..

    [JAVA] ๋ฐฑ์ค€ 11655๋ฒˆ ใ€ROT13ใ€‘

    ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ๋ฌธ์ œ ์ค‘์—์„œ ๊ฝค๋‚˜ ๋จธ๋ฆฌ๋ฅผ(?) ์“ฐ๊ฒŒ ๋งŒ๋“ค์—ˆ๋˜ ๋ฌธ์ œ๋‹ค. ๋จผ์ €, ROT๋ฌธ์ž๋Š” ๋ฌธ์ž๋ฅผ 13๊ธ€์ž์”ฉ ๋’ค๋กœ ๋ฏธ๋ฃฌ ๊ฐ’์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด A ๋ฅผ ROT ์‹์œผ๋กœ ๋ฐ”๊พธ๋ฉด 1๋ฒˆ์—์„œ 13๋ฒˆ ๋’ค์— ์žˆ๋Š” ๋ฌธ์ž์ธ N์ด ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ์œ ์˜ํ•  ์ ์ด ํ•˜๋‚˜ ์žˆ๋‹ค. O์˜ ๊ฒฝ์šฐ ROT ์‹์œผ๋กœ ๋ฌธ์ž๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด Z๋ฅผ ๋„˜์–ด์„œ ๋‹ค์‹œ ๋ฌธ์ž์˜ ์ˆœ์„œ๊ฐ€ A๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— B๊ฐ€ ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ , ์†Œ๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋ฅผ ์œ ์ง€ํ•ด์•ผํ•˜๊ณ  ๋Œ€๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋ฅผ ์œ ์ง€ํ•ด์•ผํ•œ๋‹ค. ๋งŒ์•ฝ, ์šฐ๋ฆฌ๊ฐ€ 'a'์˜ ์•„์Šคํ‚ค์ฝ”๋“œ๊ฐ€ ๋ช‡์ธ์ง€ ๋ชฐ๋ผ๋„, [์ž…๋ ฅ๋˜๋Š” ๋ฌธ์ž - 'a'] ์˜ ๊ฐ’์€ 0 ์—์„œ 25๊นŒ์ง€์ž„์€ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด, 'a'-'a' ~ 'z'-'a' ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. [์ž…๋ ฅ๋˜๋Š” ๋ฌธ์ž - 'a']+13 ์ด 'a'์˜ ์œ„์น˜๋ฅผ 0์œผ๋กœ ์žก์•˜์„ ๋•Œ, 13๋ฒˆ์งธ..

    [JAVA] ๋ฐฑ์ค€ 2743๋ฒˆ ใ€๋‹จ์–ด ๊ธธ์ด ์žฌ๊ธฐใ€‘

    ๋‹จ์–ด์˜ ๊ธธ์ด๋ผ... ๋„ˆ๋ฌด ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ๋ผ์„œ ํ• ๋ง์ด ์—†๋‹ค. ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›์€๋’ค, length() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ”๋กœ ๋‹ต์ด ๋‚˜์˜จ๋‹ค. ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ์œ ํ˜•์ด , ์ด์ „์— ํ’€์—ˆ๋˜ Dp๋‚˜ ์ •๋ ฌ ์œ ํ˜•์— ๋น„ํ•ด ๋งค์šฐ ์‰ฌ์šด ๊ฒƒ ๊ฐ™๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); S..

    [JAVA] ๋ฐฑ์ค€ 10820๋ฒˆ ใ€๋ฌธ์ž์—ด ๋ถ„์„ใ€‘

    String์œผ๋กœ ์ž…๋ ฅ๋ฐ›์€ ๋’ค์— charAt() ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์กฐ๊ฑด์„ ๋”ฐ์ ธ๋ณด๊ณ , ํ•ด๋‹นํ• ๋•Œ๋งˆ๋‹ค ์นด์šดํŒ…ํ•ด์ฃผ๋ฉด ๋˜๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€๋‹ค! ์กฐ๊ฑด์‹์„ ๋‚˜๋Š” ๋ฌธ์žํ˜• ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ‘œํ˜„ํ–ˆ๋Š”๋ฐ, ์•„์Šคํ‚ค ์ฝ”๋“œ๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด, ์•„์Šคํ‚ค ์ฝ”๋“œ๋กœ ์กฐ๊ฑด์‹์„ ์ž‘์„ฑํ•ด๋„ ๋œ๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; //์†Œ๋ฌธ์ž ๋Œ€๋ฌธ์ž ์ˆซ์ž ๊ณต๋ฐฑ ๊ฐฏ์ˆ˜ ๊ตฌํ•˜๊ธฐ public class Main { public static void main(String[] args) throws IOException { BufferedRea..

    [JAVA] ๋ฐฑ์ค€ 10809๋ฒˆ ใ€์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐใ€‘

    ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜๋งŒ ์•Œ๋ฉด ๋˜๊ธฐ๋•Œ๋ฌธ์—, ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋ฅผ key ๊ฐ’์œผ๋กœ ํ•˜๊ณ  value ๊ฐ’์„ -1์œผ๋กœ ์ดˆ๊ธฐ์„ค์ •ํ•œ ๋’ค, key์— ํ•ด๋‹นํ•˜๋Š” value ๊ฐ’์ด -1์ธ ๊ฒฝ์šฐ์—๋งŒ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด, ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜๋งŒ ๊ธฐ๋กํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฐธ๊ณ ๋กœ, ์ดˆ๊ธฐ๊ฐ’์ด -1๋กœ ๋“ฑ๋ก๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์—, countMap.get(input.charAt(i)) + 1+ i ๋กœ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ์—ฌ์•ผ ํ•œ๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; //baekjoon ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜ //1 0 -1 -1 2 -1 -1 -1 -1..

    [JAVA] ๋ฐฑ์ค€ 10808๋ฒˆ ใ€์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜ใ€‘

    ์•ŒํŒŒ๋ฒณ ๊ฐฏ์ˆ˜ ์„ธ๋Š” ๊ฒƒ์€ Map์„ ์‚ฌ์šฉํ•˜๋ฉด ๋งค์šฐ ๊ฐ„๋‹จํ•˜๋‹ค. ๋จผ์ €, ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ž…๋ ฅ๋˜๊ณ , 0๋ฒˆ๋‚˜์˜จ ๊ฒฝ์šฐ์—๋„ ์ถœ๋ ฅํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—. ํ‚ค ๊ฐ’์œผ๋กœ๋Š” ์•ŒํŒŒ๋ฒณ 'a'~'z' ๊นŒ์ง€ ๋„ฃ๊ณ  value ๊ฐ’์„ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ์‹œ์ผœ์ค€๋‹ค. ๊ทธ๋ฆฌ๊ณ  map.put(key,map.get(key)+1) ์„ ์‚ฌ์šฉํ•˜์—ฌ ํšŸ์ˆ˜๋ฅผ ์„ธ๋ฉด ๋œ๋‹ค. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws IOException { Map count..