[SWEA] String Posted on 2019-12-12 | In Problem_Solving | 문제 보러가기 제한사항 한 문장에서 검색하는 문자열의 길이는 최대 10을 넘지 않는다. 한 문장에서는 하나의 문자열만 검색한다. Code 1234567891011121314151617181920212223import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); for(int T=1;T<=10;T++) { int tc = sc.nextInt(); sc.nextLine(); String target = sc.nextLine(); String str = sc.nextLine(); str = str.replaceAll(target, "+"); int count = 0; for(int i=0; i<str.length(); i++) { if ( str.charAt(i) == '+' ) { count++; } } System.out.println("#"+tc+" "+count); } } } 123456789101112131415161718192021222324import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); for(int tc=1; tc<=10; tc++) { int T = s.nextInt(); String f = s.next(); int len = f.length(); String str = s.next(); int count =0; for(int i=0; i<str.length()-len+1; i++) { //System.out.println(str.substring(i,i+len)); if(f.equals(str.substring(i, i+len))) { count++; } } System.out.println("#"+T+" "+count); } } }