본문 바로가기

알고리즘 · 코딩

[SWEA 1213] String

SWEA 1213. [S/W 문제해결 기본] 3일차 - String 

문제 링크

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14P0c6AAUCFAYi#none 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


C++ 풀이

#include <iostream>
#include <string.h>
using namespace std;

int main() {
	string sentence, word;
	for (int i = 1; i <= 10; ++i) {
		int tc_num, count = 0, index = 0;
		cin >> tc_num >> word >> sentence;
		int word_length = word.length();
		while (index < sentence.length() - word_length + 1) {
			if (word == sentence.substr(index, word_length)) {
				count++;
				index += word_length;
			}
			else
				index++;
		}
		cout << "#" << i << " " << count << endl;
	}
}

 

 

 

LIST

'알고리즘 · 코딩' 카테고리의 다른 글

[SWEA 1215] 회문1  (0) 2021.10.21
[SWEA 1221] GNS  (0) 2021.10.21
[SWEA 1245] 균형점  (0) 2021.10.20
[SWEA 1266] 소수 완제품 확률  (0) 2021.10.19
[SWEA 1206] View  (0) 2021.10.18