• Home
  • About
    • on Weekend photo

      on Weekend

      ๐™Ž๐™ฉ๐™ช๐™™๐™ฎ๐™ž๐™ฃ๐™œ

    • Learn More
    • Instagram
    • Github
  • Archive
    • All Posts
    • All Tags
    • All Categories
  • Categories
    • Problem Solving
    • TIL
    • Study
    • Etc
    • ํ•„์‚ฌ
  • Projects

[๋ฐฑ์ค€] 1316

06 Dec 2020

์ฝ”๋“œ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โ€˜๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปคโ€™ ๋ฌธ์ œ ํ™•์ธ

ํ’€์ด

๊ทธ๋ฃน ๋‹จ์–ด๋ž€, ๋‹จ์–ด์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด์„œ, ๊ฐ ๋ฌธ์ž์— ์—ฐ์†ํ•ด์„œ
๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋งŒ์„ ๋งํ•œ๋‹ค. ๊ฐ€๋ น, ccazzzzbb๋Š” cazb๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚œ๋‹ค. kin๋„ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚œ๋‹ค.
aabbccb๋Š” abc์— b๊ฐ€ ๋–จ์–ด์ ธ์„œ ๋‚˜ํƒ€๋‚˜๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ฃน ๋‹จ์–ด๊ฐ€ ์•„๋‹ˆ๋‹ค.

๊ทธ๋ฃน๋‹จ์–ด ํŒ๋ณ„์€ ์–ด๋–ป๊ฒŒ?
boolean ๋ฐฐ์—ด์ด๋ฉด ๋  ๊ฒƒ ๊ฐ™์Œ, ๊ฐ ์•ŒํŒŒ๋ฒณ(26) ๋ถ€์šธ ๋ฐฐ์—ด์„ ์„ ์–ธํ•˜๊ณ , ํ•ด๋‹น ์•ŒํŒŒ๋ฒณ์ด ์ฒ˜์Œ์œผ๋กœ ๋“ฑ์žฅํ•˜๋ฉด true๋กœ ๋ฐ”๊พผ๋‹ค. ๋‹จ, ์—ฐ์†๋˜์–ด ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋”์ด์ƒ ์—ฐ์†๋˜์ง€ ์•Š์„ ๋•Œ๊นŒ์ง€ i++ํ•˜์—ฌ ๋‹ค์Œ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋™ํ•œ๋‹ค.

์ฝ”๋“œ

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

bool alpha[26] = { false, };

int main()
{
	int T;
	cin >> T;

	int cnt = 0;
	while (T--) {
		for (int i = 0; i < 26; i++) alpha[i] = false;
		string str;
		cin >> str;
		bool group_word = true;
		for (int i = 0; i< int(str.length());i++) {
			int idx = int(str[i] - 'a');
			if (alpha[idx] == false)
			{
				alpha[idx] = true;
				while (str[i + 1] == str[i]) i++;
			}
			else group_word = false;
		}
		if (group_word) cnt++;

	}
	cout << cnt;
	return 0;
}



problem_solvingc++ Share Tweet +1