Official

A - Digit Machine 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 to 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.


Let \(num\) be the number shown on the screen.
Initially, \(num = 0\).

By pressing the button once, \(num\) changes to \(a_{num}\). Repeat this operation \(3\) times.

The following is a sample code in C++.

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

signed main(){
    vector<ll>a(10);
    for(int i=0;i<=9;i++){
        cin>>a[i];
    }

    ll num = 0; // Initially, 0 is shown on the screen

    num = a[num]; // The button has been pressed once
    num = a[num]; // The button has been pressed twice
    num = a[num]; // The button has been pressed 3 times

    cout<<num<<endl;

    return 0;
}

posted:
last update: