返回顶部

奶牛洗牌

注意这道题要考虑负数!不然数组越界RE

#include <bits/stdc++.h>
using namespace std;
int n,a[105];
string t[105],cow[105];

int main(){
    cin>>n;
    for (int i=1;i<=n;i++)cin>>a[i];
    for (int i=1;i<=n;i++)cin>>cow[i];

    for (int i=1;i<=3;i++){
        for (int j=1;j<=n;j++){
            t[j] = cow[a[j]]; // 临时数组,按题目所说 a[j] 当调换的前
        }
        for (int j=1;j<=n;j++){
            cow[j] = t[j]; // 2022年1月22日18点39分,看的是j下标
        }
    }
    for (int i=1;i<=n;i++){
        cout<<cow[i]<<endl;
    }
    // system("pause");
    return 0;

}

提交记录

posted @ 2022-01-22 18:42  zrc4889  阅读(35)  评论(0编辑  收藏  举报