문제 링크: https://www.acmicpc.net/problem/1316
백준 문자열 10단계 - 1316번 그룹 단어 체커를 풀어보았다.
풀이: 글자를 비교해 그룹 단어를 판단한다.
C++
#include <iostream>
using namespace std;
int main()
{
int cnt;
cin>>cnt;
int res=0;
for(int i=0;i<cnt;i++)
{
string inp;
cin>>inp;
bool alpha[26]={false};
bool check=true;
for(int j=0;j<inp.length();j++)
{
if(alpha[inp[j]-'a'])
{
check=false;
break;
}
alpha[inp[j]-'a']=true;
char k=inp[j];
while(1)
{
if(k!=inp[++j])
{
j-=1;
break;
}
}
}
if(check==true) res+=1;
}
cout<<res;
}
Python
n=int(input())
cnt=n
for i in range(n):
word=input()
for j in range(0,len(word)-1):
if word[j]==word[j+1]: pass # 글자가 같으면 넘어가고
elif word[j] in word[j+1:]: # 글자가 다를때 그 글자가 뒤에 또 있다면
cnt-=1 # 그룹단어의 수를 뺀다
break
print(cnt)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
벌집 풀이 (0) | 2023.01.02 |
---|---|
손익분기점 풀이 (0) | 2023.01.02 |
크로아티아 알파벳 풀이 (0) | 2023.01.02 |
다이얼 풀이 (0) | 2023.01.02 |
상수 풀이 (0) | 2023.01.02 |