1. What I learned

    How to initialize an array

        When initializing an array with a single number, ‘fill_n(ARRAY, LENGTH_OF_ARRAY, NUMBER_TO_INITIALIZE)’ can be used.

2. Code

#include <iostream>

using namespace std;

int main(void) {
    string str;
    int idx = 0;
    int chs[26];
    fill_n(chs, 26, -1);
    
    cin >> str;

    while (str[idx] != '\0') {
        if (chs[str[idx]-97] == -1) {
            chs[str[idx]-97] = idx;
        }
        idx++;
    }

    for (int i=0 ; i<26 ; i++) {
        if (i == 25) {
            cout << chs[i] << '\n';
            break;
        }
        cout << chs[i] << ' ';
    }
    return 0;
}

3. Result

        Runtime : 0 ms, Memory usage : 2016 KB
        (Runtime can be different by a system even if it is a same code.)

Check out the my GitHub repo for more info on the code. If you have questions, you can leave a reply on this post.