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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <algorithm> #include <iostream> #include <string> bool alphabet[26]; int alphaIndex; int count; bool is_pangram(const char *str) { if (strlen(str) < 26) { return false; } for (size_t index = 0; index < strlen(str); index++) { if (str[index] >= 'A' && str[index] <= 'Z') { alphaIndex = str[index] - 'A'; } else if (str[index] >= 'a' && str[index] <= 'z') { alphaIndex = str[index] - 'a'; } else { continue; } if (!alphabet[alphaIndex]) { alphabet[alphaIndex] = true; if (++count == 26) { return true; } } } return false; } int main() { std::string str; std::cin >> str; std::cout << is_pangram(str.c_str()) << '\n'; } | cs |
최적화방법 생각나면 고쳐올게용;
댓글 0