알고리즘 · 코딩
[SWEA 3143] 가장 빠른 문자열 타이핑
G A
2020. 12. 26. 22:16
문제 링크
swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV_65wkqsb4DFAWS
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
C++ 풀이
#include <iostream>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T , c, A_length, B_length, pos;
string A, B;
cin >> T;
for (int i = 1; i <= T; i++) {
cin >> A >> B;
pos = 0; c = 0;
A_length = A.length();
B_length = B.length();
while (pos < A_length) {
if ((pos <= A_length - B_length) && (A.substr(pos, B_length) == B))
pos += B_length;
else
pos++;
c++;
}
cout << "#" << i << " " << c << "\n";
}
return 0;
}
반응형