BOJ-1543번
카테고리
-
문자열
-
그리디 알고리즘
-
브루트포스 알고리즘
아이디어
코드
#include <iostream>
#include <string>
using namespace std;
int Check_Keyword_Num(string target, string check);
int main() {
string a, b;
getline(cin, a);
getline(cin, b);
cout << Check_Keyword_Num(a, b);
return 0;
}
int Check_Keyword_Num(string target, string check) {
if (target.length() < check.length())
return 0;
int num = 0;
for (int i = 0; i <= target.length() - check.length(); i++) {
for (int j = 0; j < check.length(); j++) {
if (target[i + j] != check[j])
break;
if (j == check.length() - 1) {
num++;
i = i + j;
}
}
}
return num;
}
주의할 반례
- 검색 문자열이 더 큰 경우가 존재할 수 있다.
Author And Source
이 문제에 관하여(BOJ-1543번), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@abrahamkim98/BOJ-1543번
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
문자열
그리디 알고리즘
브루트포스 알고리즘
코드
#include <iostream>
#include <string>
using namespace std;
int Check_Keyword_Num(string target, string check);
int main() {
string a, b;
getline(cin, a);
getline(cin, b);
cout << Check_Keyword_Num(a, b);
return 0;
}
int Check_Keyword_Num(string target, string check) {
if (target.length() < check.length())
return 0;
int num = 0;
for (int i = 0; i <= target.length() - check.length(); i++) {
for (int j = 0; j < check.length(); j++) {
if (target[i + j] != check[j])
break;
if (j == check.length() - 1) {
num++;
i = i + j;
}
}
}
return num;
}
주의할 반례
- 검색 문자열이 더 큰 경우가 존재할 수 있다.
Author And Source
이 문제에 관하여(BOJ-1543번), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@abrahamkim98/BOJ-1543번
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#include <iostream>
#include <string>
using namespace std;
int Check_Keyword_Num(string target, string check);
int main() {
string a, b;
getline(cin, a);
getline(cin, b);
cout << Check_Keyword_Num(a, b);
return 0;
}
int Check_Keyword_Num(string target, string check) {
if (target.length() < check.length())
return 0;
int num = 0;
for (int i = 0; i <= target.length() - check.length(); i++) {
for (int j = 0; j < check.length(); j++) {
if (target[i + j] != check[j])
break;
if (j == check.length() - 1) {
num++;
i = i + j;
}
}
}
return num;
}
- 검색 문자열이 더 큰 경우가 존재할 수 있다.
Author And Source
이 문제에 관하여(BOJ-1543번), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@abrahamkim98/BOJ-1543번저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)