SWEA::문제풀이
3143 가장 빠른 문자열 타이핑
2영재
2018. 2. 24. 15:22
3143 가장 빠른 문자열 타이핑
1. a문자열에서 b문자열이 몇번 나오는지 카운팅
2. a문자열길이 - (cnt * b문자열길이) + cnt 출력
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 | #include <iostream> #include <string> #include <algorithm> using namespace std; int t; string a, b; int main() { ios_base::sync_with_stdio(false); cin >> t; for (int tc = 1; tc <= t; tc++) { cin >> a >> b; int cnt = 0; int idx = 0; int alen = a.length(); int blen = b.length(); while (true) { int pos = a.find(b, idx); if (pos == string::npos) break; cnt++; idx = pos + blen - 1; } cout << "#" << tc << " " << alen - (cnt*blen) + cnt << "\n"; } } | cs |