Jun's Development Journey

[SWEA] 1213. [S/W 문제해결 기본] String - String 본문

SWEA/Intermediate

[SWEA] 1213. [S/W 문제해결 기본] String - String

J_Jayce 2019. 8. 2. 12:40

문제

https://www.swexpertacademy.com/main/learn/course/lectureProblemViewer.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

www.swexpertacademy.com

 

 

풀이

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
 
public class Solution {
    static Scanner scan = new Scanner(System.in);
    static String test, sub;
 
    static int get_sub_num() {
        int answer = 0;
        int sub_len = sub.length();
        for(int i=0;i<=test.length()-sub_len;i++) {
            if(test.substring(i, i+sub_len).equals(sub))
                answer++;
        }
        return answer;
    }
    static void solution() {
        for(int i=1;i<=10;i++) {
            scan.nextInt();
            sub = scan.next();
            test = scan.next();
            System.out.println("#"+i+" "+get_sub_num());
        }
    }
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        solution();
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter