Cute Blue Flying Butterfly
본문 바로가기
알고리즘

[C++] SWEA [SW 문제해결 기본] 3일차 - String

by jordancancode 2024. 11. 19.

출처

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14P0c6AAUCFAYi




풀이

#include <bits/stdc++.h>
using namespace std;

int search(string target, string sentence) {
	int cnt = 0;
	for (int i = 0; i < sentence.size()-target.size()+1; i++) {
		if (sentence.substr(i, target.size()) == target) { cnt++; }
	}
	return cnt;
};

int main() {
	for (int t = 1; t <= 10; t++) {
		int T, result;
		string target, sentence;
		cin >> T;
		cin >> target >> sentence;
		result = search(target, sentence);
		cout << "#" << t << " " << result << endl;
	}
}
반응형