[Atcoder]ABC241 A - Digit Machine

题目

Score : 100 points

Problem Statement

There is a device with a screen that shows a single-digit number, and a button.

When the screen is showing a number kk, pressing the button once changes the number on the screen to akak.

The device currently shows 00. After pressing the button 33 times, what will be shown on the screen?

Constraints

  • 0≤ai≤9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

a0 a1 …… a9

Output

Print the answer.


Sample Input 1

9 0 1 2 3 4 5 6 7 8

Sample Output 1

7

The number on the screen transitions as 0→9→8→7.


Sample Input 2

4 8 8 8 0 8 8 8 8 8

Sample Output 2

4

The number on the screen transitions as 0→4→0→4.


Sample Input 3

0 0 0 0 0 0 0 0 0 0

Sample Output 3

0

题目翻译及分析

       给你9个数,a0,a1...a9。刚开始取0为初始位置,然后转移到a0位置,再转移到a[a[0]]位置...,这样转3次就好了。

       先把a数组读入。然后可以直接printf("%d",a[a[a[0]]]),也可以用循环,我写的是用循环。

代码

#include<bits/stdc++.h> 
using namespace std; 
int n,i,a[10]; 
int main(){ 
    for(i=0;i<10;++i) scanf("%d",&a); 
    n=3,i=a[0]; //第一次
    while(--n) i=a[i]; //再来两次
    printf("%d",i); 
    return 0; 
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值