๋ฐ์ํ
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// 2941 ํฌ๋ก์ํฐ์ ์ํ๋ฒณ
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String word = in.next();
in.close();
final String[] cr = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="};
int cnt = 0;
for (int i = 0; i < cr.length; i++) {
Pattern p = Pattern.compile(cr[i]);
Matcher m = p.matcher(word);
while (m.find()) {
cnt++;
}
word = word.replace(cr[i], " ");
}
System.out.print(cnt + word.replace(" ", "").length());
}
}
- ํฌ๋ก์ํฐ์ ์ํ๋ฒณ์ cr๋ฐฐ์ด์ ๋ด์ for๋ฌธ์ ๋๋ฆฌ๋๋ฐ
- Pattern&Matcher๋ฅผ ์ฌ์ฉํด ๊ฐฏ์cnt๋ฅผ ์ธ์ค๋๋ค.
- ๋จ๋ ๊ธ์๋ค์ ๊ธธ์ด๋ฅผ ์ฐ ํ cnt์ ํฉ์ณ์ฃผ๋ฉด ๋ฉ๋๋ค.
๋ฐ์ํ
'๐ธ Algorithm > ๐ธ ๋ฐฑ์ค BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][java][25206][๋์ ํ์ ์] (1) | 2024.02.24 |
---|---|
[๋ฐฑ์ค][java][1316][๊ทธ๋ฃน ๋จ์ด ์ฒด์ปค] (0) | 2024.02.13 |
[๋ฐฑ์ค][java][1157][๋จ์ด ๊ณต๋ถ] (1) | 2024.02.08 |
[๋ฐฑ์ค][java][10988][ํฐ๋ฆฐ๋๋กฌ์ธ์ง ํ์ธํ๊ธฐ] (0) | 2024.02.07 |
[๋ฐฑ์ค][java][2444][๋ณ ์ฐ๊ธฐ - 7] (0) | 2024.02.04 |