๐Ÿ‘จ๐Ÿป‍๐Ÿ’ป PS

    [JAVA] ๋ฐฑ์ค€ 1463๋ฒˆ ใ€1๋กœ ๋งŒ๋“ค๊ธฐใ€‘

    Dynamic Programing์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๋จผ์ €, ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ํ•ด๋‘˜ dp[ ] ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•œ๋‹ค. dp[n]์˜ ์˜๋ฏธ๋Š” n์—์„œ 1๋กœ ๋ณ€ํ™˜ํ• ๋•Œ ๋“œ๋Š” ์ตœ์†Œ์˜ ์—ฐ์‚ฐ์ˆ˜๋ฅผ ์ €์žฅํ•  ๊ฒƒ์ด๋‹ค. ๋จผ์ € dp[0] ๊ณผ dp[1] ์˜ ๊ฐ’์ด 0 ์ž„์€ ๋ช…ํ™•ํ•œ ์‚ฌ์‹ค์ด๊ณ , dp[2]๋ถ€ํ„ฐ ์กฐ๊ฑด๋ฌธ์„ ์ด์šฉํ•ด ์ •์˜๋ฅผ ํ•œ๋‹ค. 2๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ํšŸ์ˆ˜์˜ ์ตœ์†Ÿ๊ฐ’์€ ๋ฌด์—‡์ผ๊นŒ. ๋จผ์ € 2๊ฐ€์ง€ ์—ฐ์‚ฐ์„ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. 1์„ ๋นผ๊ฑฐ๋‚˜, 2๋ฅผ ๋‚˜๋ˆ„๋Š” ๊ฒƒ 2-1 = 1 ์ด๋ฏ€๋กœ dp[2]=dp[1]+1=0+1=1 2/2=1 ์—ญ์‹œ, dp[2]=dp[1]+1=0+1=1์ด๋‹ค. ๋‘˜๋‹ค ๊ฐ’์ด 1์ด๋ฏ€๋กœ ๋‘ ์—ฐ์‚ฐ์˜ ์ตœ์†Ÿ๊ฐ’์€ 1์ด๋‹ค. 2์—์„œ 1๋กœ ๋งŒ๋“œ๋Š” ์—ฐ์‚ฐ์˜ ์ตœ์†Ÿ๊ฐ’์€ 1์ด๋ฏ€๋กœ, dp[2]=1์„ ๊ธฐ๋กํ•œ๋‹ค. 3์„ 1๋กœ ๋งŒ๋“œ๋Š” ํšŸ์ˆ˜์˜ ์ตœ์†Ÿ๊ฐ’์€? 3์€ 1์„ ๋นผ๊ฑฐ๋‚˜ 3์„ ๋‚˜๋ˆ„..

    [JAVA] ๋ฐฑ์ค€ 2522๋ฒˆ ใ€๋ณ„ ์ฐ๊ธฐ - 12ใ€‘

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); for(int i=1;i

    [JAVA] ๋ฐฑ์ค€ 1924๋ฒˆ ใ€2007๋…„ใ€‘

    ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๊ฒ ์ง€๋งŒ, ์‹ค์ œ๋กœ 2007๋…„ 1์›” 1์ผ์ด ์›”์š”์ผ์ด๋ฏ€๋กœ, ๋‚˜๋Š” ๋ฐฐ์› ๋˜ Calendar class ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. [JAVA] Calendar class ์ •๋ฆฌ Calendar ํด๋ž˜์Šค Calendar ํด๋ž˜์Šค๋Š” ์ถ”์ƒ ํด๋ž˜์Šค์ด๋ฏ€๋กœ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์—†๊ณ , getInstance๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด์•ผ ํ•œ๋‹ค. Calendar cal = Calendar.getInstance(); ์›๋ž˜ ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๋‹ค๋ฃฐ ๋ชฉ์ ์œผ๋กœ ์ œ.. yinq.tistory.com import java.util.Calendar; import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new ..

    [JAVA] ๋ฐฑ์ค€ 11721๋ฒˆ ใ€์—ด ๊ฐœ์”ฉ ๋Š์–ด ์ถœ๋ ฅํ•˜๊ธฐใ€‘

    charAt๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅ์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์ง€๋งŒ, ๋‚˜๋Š” substring ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด๋ณด์•˜๋‹ค. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String Input = scanner.next(); print10(Input); } static void print10(String Input) { int length = Input.length(); for(int i=0;i

    [JAVA] ๋ฐฑ์ค€ 11718๋ฒˆ ใ€๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐใ€‘

    Scanner๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์ง€๋งŒ, BufferedReader๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค. import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String txt; while((txt=br.readLine())!=null) { // ์ž…๋ ฅ์ด ์žˆ๋‹ค๋ฉด ์ถœ๋ ฅํ•˜๋„๋ก ์กฐ๊ฑด๋ฌธ ์„ค์ • System.out.println(txt); } } } BufferedReader ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ ํ›„, txt๋ผ๋Š” ๋ฌธ์ž์—ด์„ ์„ ์–ธํ•˜์˜€๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ txt์— br.readLine() ๋ฅผ..