Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- Algorithm
- 안드로이드
- utility
- hackerrank
- modern C++
- RAII
- Android
- 2019 카카오 개발자 겨울 인턴십
- 백트랙
- 2018 KAKAO BLIND RECRUITMENT
- BOJ
- backtrack5
- unique_ptr
- setting
Archives
- Today
- Total
K-D²
Pangrams 본문
HackerRank > Practice > Algorithms > Strings > Pangrams
문제 링크 : www.hackerrank.com/challenges/pangrams/problem
a-z까지의 모든 알파벳이 나타나면 'pangram'이라고 한다. (대소문자를 별도로 구분하지 않는다.)
문자가 공백일수도 있으므로 알파벳인지 확인하고, 대소문자에 따라 적절히 인덱스 값을 구하여 해당 알파벳이 사용되었음을 체크한다.
'pangram' 인 경우 'pangram'을 출력하고, 그렇지 않은 경우 'not pangram'을 출력한다.
#include <bits/stdc++.h>
using namespace std;
// Complete the pangrams function below.
string pangrams(string s) {
bool chk[26] = { false };
for (char c : s) {
int idx;
if (c >= 'A' && c <= 'Z') {
idx = c - 'A';
chk[idx] = true;
}
else if (c >= 'a' && c <= 'z') {
idx = c - 'a';
chk[idx] = true;
}
}
for (int i = 0; i != 26; ++i) {
if (!chk[i]) {
return "not pangram";
}
}
return "pangram";
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string result = pangrams(s);
fout << result << "\n";
fout.close();
return 0;
}
Comments