Official

A - Generalized ABC Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.


In this problem, you need to find the \(i\)-th character of the alphabet. There are several ways to do so. In C++, you can write char('A' + i); in Python, chr(ord('A') + i).

Note that many programming languages adopt 0-based indexing; both in C++ and Python, A is considered the 0-th character, B the 1-st, and so on.

All that left is to print the \(0\)-th through \((K-1)\)-th characters of the alphabet. You can use a for statement for this purpose. There is a sample code below. If you do not understand, see also the editorials for Problem A in AtCoder Beginners Contest 272 and later, as they also require a for statement.

Sample code (C++):

#include <bits/stdc++.h>
using namespace std;

int main() {
    int k;
    cin >> k;
    for(int i = 0; i < k; i++) {
        cout << char('A' + i);
    }
}

Sample code (python):

k = int(input())
for i in range(k):
    print(chr(ord('A') + i), end = '')

posted:
last update: