본문 바로가기
알고리즘 & 자료구조/백준

백준 1543

by 신재권 2022. 8. 7.
package baekjoon.그리디;

import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main1543 {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String A = br.readLine();
		String B = br.readLine();

		int al = A.length();
		int bl = B.length();

		int ans = 0;

		for (int i = 0; i < al - bl + 1; ) {
			boolean c = true;
			for (int j = 0; j < bl; j++) {
				if (A.charAt(i + j) != B.charAt(j)) {
					c = false;
				}
			}
			if (!c) {
				i++;
			} else {
				ans++;
				i += bl;
			}
		}

		System.out.println(ans);
	}
}

 

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 2437  (0) 2022.08.10
백준 1080  (0) 2022.08.08
백준 2864  (0) 2022.08.04
백준 1744  (0) 2022.08.03
백준 1202  (0) 2022.08.01