πŸ˜‰/μ½”λ”©ν…ŒμŠ€νŠΈ

[μ•Œκ³ λ¦¬μ¦˜] ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³ (λ°±μ€€, 2941)

ruhz 2021. 3. 3. 17:44

문제

 

2941번: ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³

μ˜ˆμ „μ—λŠ” μš΄μ˜μ²΄μ œμ—μ„œ ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³μ„ μž…λ ₯ν•  μˆ˜κ°€ μ—†μ—ˆλ‹€. λ”°λΌμ„œ, λ‹€μŒκ³Ό 같이 ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³μ„ λ³€κ²½ν•΄μ„œ μž…λ ₯ν–ˆλ‹€. ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³ λ³€κ²½ č c= Δ‡ c- dΕΎ dz= Δ‘ d- lj lj nj nj š s= ΕΎ z=

www.acmicpc.net

 

풀이

 

ruhz3/CodingTest

To prepare for coding test. Contribute to ruhz3/CodingTest development by creating an account on GitHub.

github.com

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

string word;
static string croats[8] = {
	"c=", "c-", "dz=", "d-",
	"lj", "nj", "s=", "z=" };


int count() {
	int len = word.size();
	int cnt = len;
	string buf;
	
	// 버퍼에 첫 κΈ€μžλ₯Ό λ‹΄λŠ”λ‹€.
	for (int i = 0; i < len; i++) {
		buf.clear();
		buf.push_back(word[i]);

		// 담은 κΈ€μž 뒀에 2κ°œκΉŒμ§€ 버퍼에 λ‹΄μ•„ κ²€μ‚¬ν•œλ‹€.
		for (int j = 1; j < 3; j++) {
			if ((i + j) >= len)
				break;
			buf.push_back(word[i+j]);

			// 찾은 단어λ₯Ό κ°―μˆ˜μ— λ°˜μ˜ν•˜κ³ , λ‹€μŒ 검사할 μ²«κΈ€μžλ₯Ό 찾은 단어 λ’€λ‘œ ν•΄μ€€λ‹€.
			for (int k = 0; k < 8; k++) {
				if (buf.compare(croats[k]) == 0) {
					cnt -= (croats[k].size() - 1);
					i += (croats[k].size() - 1);
					break;
				}
			}
		}
	}
	return cnt;
}


int main() {
	cin >> word;
	cout << count() << endl;

	return 0;
}

λ¬Έμžμ—΄ 뢀뢄은 μ–΄λ ΅κ²Œ λ‚˜μ˜€μ§„ μ•Šμ•„λ„ μ€κ·Όνžˆ κΉŒλ‹€λ‘­κ³ , λΌμ΄λΈŒλŸ¬λ¦¬κ°€ λ§Žμ•„ 자꾸 까먹게 λ˜λ‹ˆ 자주 ν’€μ–΄λ³΄μž.