๋ฐ์ํ
https://codeforces.com/problemset/problem/1095/A
์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String str = scan.next();
String result = "";
int index = 0;
for(int i=0; i<str.length(); i++) {
if(index >= str.length())
break;
result += str.charAt(index);
index += (i+1);
}
System.out.println(result);
scan.close();
}
}
ํ์ด
๋ฌธ์์ด s = s1s2 ... sm ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์๋, ์ํธ์ ๊ท์น์ ์๋์ ๊ฐ๋ค.
s1์ ํ๋ฒ์ฐ๊ณ , s2๋ ๋๋ฒ์ฐ๊ณ , s3์ 3๋ฒ์ฐ๊ณ , ... sm์ m๋ฒ ์ด๋ค.
s = bab๋ผ๋ฉด b aa bbb -> baabbb ๊ฐ ๋๋ค.
๋ฐ๋ผ์ ์ฒ์ ์ฌ์ฉ๋ ๋ฌธ์๋ง ๋ฝ์์๋ค.
s.charAt(0) + s.charAt(1) + s.charAt(3) + s.charAt(6) + s.charAt(10) + ...
์ด๋ฐ์์ผ๋ก charAt() ์์ ๋ค์ด๊ฐ๋ ๊ฐ์ ๋ฑ์ฐจ์์ด์ ์ด๋ค์ index += (i+1) ๋ก ํด๊ฒฐํ๋ค.
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 17478๋ฒ: ์ฌ๊ทํจ์๊ฐ ๋ญ๊ฐ์?(์ฌ๊ท) (0) | 2020.03.10 |
---|---|
[Codeforces] 1207A: There Are Two Types Of Burgers (0) | 2020.03.10 |
[Codeforces] 1077A: Frog Jumping (0) | 2020.03.08 |
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ์์ฐ (0) | 2020.03.08 |
[Codeforces] 1285A: Mezo Playing Zoma (0) | 2020.03.08 |
๋๊ธ