Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
6857 邓小龙 19按规则查找数组中的数据 C++ Accepted 0 MS 276 KB 643 2025-03-22 16:11:24

Tests(10/10):


Code:

# include<iostream> // cin\cout\endl using namespace std; int a[1010],n,m;//a数组用于存n个数,m代表要查找的次数 int main(){ //1.录入n,m cin>>n>>m; //2.录入n个数存入数组a for(int i=1;i<=n;i++){ cin>>a[i]; } //3.寻找m个数 //第一个数一定是a[1] //cout<<a[1]<<" "; //int t=a[1];//第二个数的下标 //从第二个数开始输出,直到第m个数输出来 int t=1;//第一个数的下标是1 for(int i=1;i<=m;i++){ cout<<a[t]<<" "; t=a[t];//数组a下标为t的元素作为下一个数的值 } return 0; }