๐ ์ฝ๋ฉํ
์คํธ/๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค
[SWEA][JAVA]D3 : [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 3์ผ์ฐจ - String
deep_lee
2022. 11. 4. 16:29
SW Expert Academy
SW ํ๋ก๊ทธ๋๋ฐ ์ญ๋ ๊ฐํ์ ๋์์ด ๋๋ ๋ค์ํ ํ์ต ์ปจํ ์ธ ๋ฅผ ํ์ธํ์ธ์!
swexpertacademy.com
์ฐพ์ ๋ฌธ์์ด์์ ๊ฒ์์ด๊ฐ ์์ผ๋ฉด ์๋ง ์ธ๋ฉด๋๋๊น, replaceAll์ด์ฉํ์ฌ ๊ฒ์์ด๋ฅผ *๋ก ๋์ฒดํ๊ณ
*๋ฅผ ์นด์ดํ ํจ.
import java.util.Scanner;
class Solution{
public static void main(String args[]) throws Exception {
Scanner kb = new Scanner(System.in);
int[] answer=new int[10];
int cnt=0;
for(int test_case=0; test_case<10; test_case++){
int n=kb.nextInt();
String s=kb.next();
String f=kb.next();
f=f.replaceAll(s,"*");
for(char x:f.toCharArray()){
if(x=='*')
cnt++;
}
answer[test_case]=cnt;
cnt=0;
}
for(int i=0; i<answer.length; i++) System.out.println("#"+(i+1)+" "+answer[i]);
}
}