๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 1316๋ฒˆ - ๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค

by dkswnkk 2021. 11. 4.
 

1316๋ฒˆ: ๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค

๊ทธ๋ฃน ๋‹จ์–ด๋ž€ ๋‹จ์–ด์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด์„œ, ๊ฐ ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋งŒ์„ ๋งํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ccazzzzbb๋Š” c, a, z, b๊ฐ€ ๋ชจ๋‘ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ณ , kin๋„ k, i, n์ด ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ธฐ ๋•Œ

www.acmicpc.net

#include <iostream>
#include <memory.h>

using namespace std;


int cnt = 0;
bool flag = true;
void check(string s) {
    for (int i = 0; i < s.length() - 2; i++) {    
        if (s[i] != s[i + 1]) {    //1๊ณผ 2์˜ ๋‹จ์–ด๊ฐ€ ๋‹ค๋ฅผ๋•Œ
            for (int k = i + 2; k < s.length(); k++) {    //3๋ถ€ํ„ฐ ๋๊นŒ์ง€ ์ฒดํฌํ•ด 1๊ณผ ๊ฐ™์€ ๋‹จ์–ด๊ฐ€ ์žˆ๋Š”์ง€ ์ฒดํฌ
                if (s[i] == s[k]) {
                    flag = false;
                }
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    int ans = 0;
    while (N--) {
        string s; cin >> s;
        if (s.length() == 1) ans++;    //๋‹จ์–ด๊ฐ€ ํ•œ๊ธ€์ž๋ผ๋ฉด ๊ทธ๋ฃน๋‹จ์–ด์ด๋‹ค.
        else {    //๋‹จ์–ด๊ฐ€ ํ•œ๊ธ€์ž๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด    
            check(s);    //ํƒ์ƒ‰ํ•œ๋‹ค
            if (flag) ans++;
            flag = true;
        }
    }
    cout << ans;
}

๋Œ“๊ธ€