티스토리 뷰

알고리즘/SWEA

[SWEA 1213] String

히더 2018. 8. 9. 14:07

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


#include <iostream>

#include <algorithm>

#include <memory.h>

#include <string>

using namespace std;


int result;

string a, b;


int main()

{

int T; int t;

T = 10;

while (T--)

{

cin >> t; result = 0;

cin >> b >> a;

for (int i = 0; i < a.length()-(b.length()-1); i++)

{

if (a.at(i) == b.at(0))

{

int nexta = i + 1; int nextb = 1;

for (int k = 1; k < b.length(); k++)

{

if (a.at(nexta) != b.at(k)) break;

if ((a.at(nexta) == b.at(k)) && (k == b.length() - 1)) { result += 1; i+=(b.length()-1); }

nexta++;

}

}

}


cout << "#" << t << " " << result << endl;

}


return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1216] 회문2  (0) 2018.08.09
[SWEA 1215] 회문1  (0) 2018.08.09
[SWEA 1211] Ladder2  (0) 2018.08.06
[SWEA 1210] Ladder1  (0) 2018.08.06
[SWEA 1209] Sum  (0) 2018.08.06
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함