Official

A - CBC Editorial by en_translator


For beginners

This problem asks to handle strings, especially distinguishing uppercase and lowercase letters.

In case of C++, one can use the isupper function to check if a letter is an uppercase letter. Many other languages provide similar feature in their standard library.

Alternatively, one can determine it using its character code.

Let ord(x) be the character code corresponding to a letter \(x\). Then a letter \(x\) is an uppercase English letter if and only if ord('A') \(\leq \) ord(c) \(\leq\) ord('Z'), because uppercase English letters appear consecutively in the ASCII character table. Thus, one can use this condition to determine it. This approach of using character code can also be used in most programming languages.

Sample code 1(C++):

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    for (char c : s) {
        if (isupper(c)) cout << e;
    }
    cout << endl;
}

Sample code 2(C++):

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    for (char c : s) {
        if ('A' <= c && c <= 'Z') cout << e;
    }
    cout << endl;
}

Sample code 1(Python):

s = input()
ans = ""
for c in s:
    if c.isupper():
        ans += c

print(ans)

Sample code 2(Python):

s = input()
ans = ""
for c in s:
    if ord('A') <= ord(c) and ord(c) <= ord('Z'):
        ans += c

print(ans)

posted:
last update: