출처
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;
}
}
반응형
'알고리즘' 카테고리의 다른 글
투 포인터 알고리즘 Two Pointer Algorithm (1) | 2024.12.05 |
---|---|
[Kotlin] programmers 퍼즐 게임 챌린지 (0) | 2024.12.03 |
[C++] SWEA [S/W 문제해결 기본] 1일차 - Flatten (0) | 2024.11.18 |
[C++] SWEA [S/W 문제해결 응용] 2일차 - 최대 상금 (0) | 2024.11.17 |
[C++] SWEA 삼성시의 버스 노선 (0) | 2024.11.16 |