반응형
https://www.acmicpc.net/problem/10384
문자열을 이용한 구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
test case 수 t, 문자열 s를 선언한 후 입력받습니다.
📔 풀이과정
1. 특수기호와 대문자를 걸러내기 위한 함수 getFilteredStr를 수행합니다. 대문자가 있으면 소문자로 바꾸고 특수기호는 제거합니다.
2. getResultStr를 수행합니다. 알파벳이 나온 개수를 세준 후 vector alpha에 저장합니다. 이 원소들 중 최솟값이 pangram을 결정합니다.
📔 정답출력
조건에 따라 반환된 문자열을 형식에 맞게 출력합니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
string getFilteredStr(string s){
string str;
for(auto c : s){
if('A' <= c && c <= 'Z') str += c - 'A' + 'a';
else if('a' <= c && c <= 'z') str += c;
}
return str;
}
string getResultStr(string s){
int pangramCnt = 10;
vector <int> alpha(26,0);
string str = getFilteredStr(s);
for(auto c : str){
alpha[c-'a']++;
}
for(int i = 0; i < 26; i++){
pangramCnt = min(pangramCnt, alpha[i]);
}
if(!pangramCnt) return "Not a pangram\n";
if(pangramCnt == 1) return "Pangram!\n";
if(pangramCnt == 2) return "Double pangram!!\n";
return "Triple pangram!!!\n";
}
int main(){
int t;
string s;
cin >> t;
cin.ignore();
for(int testCase = 1; testCase <= t; testCase++){
getline(cin,s);
cout << "Case " << testCase << ": " << getResultStr(s);
}
}
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 23037 : 5의 수난 (0) | 2022.06.05 |
---|---|
(C++) - 백준(BOJ) 20361 : 일우는 야바위꾼 (0) | 2022.06.04 |
(C++) - 백준(BOJ) 14709 : 여우 사인 (0) | 2022.05.20 |
(C++) - 백준(BOJ) 20053 : 최소, 최대 2 (0) | 2022.05.19 |
(C++) - 백준(BOJ) 18883 : N M 찍기 (0) | 2022.05.18 |