Created
October 26, 2020 11:16
-
-
Save overnew/b587529e08010ecd991146725c82bb74 to your computer and use it in GitHub Desktop.
문서 검색 정답 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include<string> | |
using namespace std; | |
int main() { | |
string document; | |
string word; | |
int count=0; | |
getline(cin,document); | |
getline(cin,word); | |
if(document.length() <word.length()) | |
cout<<0<<'\n'; | |
else{ | |
for(int i=0; i<=document.length()-word.length() ; ++i) | |
if(document.substr(i,word.length()) == word ){ | |
++count; | |
i+= (word.length()-1); | |
} | |
cout<<count<<'\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment