※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 18813번 문제인 Divisionals Spelling이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/18813 

 

18813번: Divisionals Spelling

The first line contains two integers n (1 ≤ n ≤ 100), which is the number of words in Emilio’s list, and m (1 ≤ m ≤ 15), which is the number of questions in the contest. The next n lines describe the words. Each of these lines contains a word wit

www.acmicpc.net

각 주어지는 단어들의 1) m번째 알파벳까지의 문자로 구성되어있는지, 그리고 2) 중복된 문자가 존재하는지의 여부를 판단해 문제의 조건에 부합하는 단어의 개수를 세어주자.

 

이는 반복문과 조건문을 이용해 간단히 구현할 수 있다.

 

아래는 제출한 소스코드이다.

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

int T, L;
int visited[26];
int ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T >> L;
	while (T--) {
		memset(visited, 0, sizeof(visited));
		string s; cin >> s;
		bool chk = 1;
		for (auto& l : s) {
			int cur = l - 'A';
			if (visited[cur] || cur >= L) chk = 0;
			visited[cur] = 1;
		}

		if (chk) ans++;
	}

	cout << ans;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 5753 // C++] Pascal Library  (0) 2023.01.07
[BOJ 23365 // C++] Buffered Buffet  (1) 2023.01.06
[BOJ 15429 // C++] Odd Gnome  (0) 2023.01.06
[BOJ 21679 // C++] Клавиатура  (0) 2023.01.06
[BOJ 15083 // C++] Life Savings  (0) 2023.01.06

+ Recent posts