YJ/C++
[백준/BOJ/C++] 7600번 문자가 몇갤까
Team DAON
2021. 10. 29. 13:24
[문제]
"The quick brown fox jumped over the lazy dogs."
이 문장은 모든 알파벳이 적어도 한 번은 나오는 문장으로 유명하다.즉 26개의 서로 다른 문자를 갖고 있는 것이다.
각 케이스마다 문장에서 공백, 숫자, 특수 문자를 제외하고 얼마나 다양한 알파벳이 나왔는지를 구하면 된다. 대소문자는 하나의 문자로 처리한다. ex) 'A' == 'a'
[입력]
입력은 250자를 넘지 않는 문장이 주어진다.
각 문장은 적어도 하나의 공백이 아닌 문자를 포함한다. (알파벳이 아닐 수 있다)
마지막 줄에는 '#'이 주어진다.
[출력]
각 줄마다 출몰한 알파벳의 개수를 출력하면 된다.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<int> vector;
while(true){
string input;
getline(cin, input);
if(input == "#") break;
int alph[26];
for(int i = 0; i < 26; i++){
alph[i] = 0;
}
for(int i = 0; i < input.length(); i++){
int temp = (int)input[i];
if(temp >= 65 && temp <= 90){
temp -= 65;
alph[temp] = 1;
}
else if(temp >= 97 && temp <= 122){
temp -= 97;
alph[temp] = 1;
}
}
int count = 0;
for(int i = 0; i < 26; i++){
if(alph[i] == 1)
count++;
}
vector.push_back(count);
}
for(int i = 0; i < vector.size(); i++){
cout << vector[i] << "\n";
}
}
[결과 화면]