1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> #include <string> using namespace std; int main() { for ( int T=0; T<10;) { cin >> T; string key; string str; char key_1[10]={0}; char str_1[1000]={0}; cin >> key_1 >> str_1; key=key_1; str=str_1; int key_l=key.size(); int str_l=str.size(); int cnt = 0; for ( int i=0; i<=str.size()-key_l; i++) { if (str_1[i]==key_1[0]) //탐색시작 for ( int j=1; j<key_l; j++) { if (str_1[i+j]!=key_1[j]) break ; if (j==key_l-1) cnt++; } } cout << "#" << T << " " << cnt << endl; } } |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
171102_2178_미로탐색 (0) | 2017.11.02 |
---|---|
171101_회문1 (0) | 2017.11.01 |
171031_sum (0) | 2017.10.31 |
171030_flatten (0) | 2017.10.30 |
171030_view (0) | 2017.10.30 |