星空's Blog
PAT-A1042 Shuffling Machine

原题

Shuffling Machine (20 分)

题解

因为需要保存每一次循环结束后的状态,所以开辟2个数组用来轮换
这题最主要的是要靠清楚下标与位置的关系
一开始没转过弯来写成了交换。。。
核心代码:

card[inStream[j]] = ori[j];

代码

#include <iostream>
using namespace std;

int main(void) {
    int n;
    string card[55] = {"S0","S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13",
    "H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13",
    "C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13",
    "D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13",
    "J1","J2"};
    string ori[55];
    int inStream[55];
    cin >> n;
    for (int i = 1;i < 55;i++) {
        cin >> inStream[i];
    }
    for (int i = 0;i < n;i++) {
        for (int k = 1;k < 55;k++) {
            ori[k] = card[k];
        }
        for (int j = 1;j < 55;j++) {
            card[inStream[j]] = ori[j];
        }
    }
    for (int i = 1;i < 54;i++) {
        cout << card[i] << " ";
    }
    cout << card[54] << endl;
    return 0;
}
博客所有文章禁止转载。
算法AC代码仅供参考,请不要未经修改直接套用。
首页      算法学习      PAT-A      PAT-A1042 Shuffling Machine
https://secure.gravatar.com/avatar/271861a23dcdde929d3ee8cb8c04f854?s=256&d=monsterid&r=g

星空

文章作者

发表评论

textsms
account_circle
email

星空's Blog

PAT-A1042 Shuffling Machine
原题 Shuffling Machine (20 分) 题解 因为需要保存每一次循环结束后的状态,所以开辟2个数组用来轮换 这题最主要的是要靠清楚下标与位置的关系 一开始没转过弯来写成了交换。。。 核心代…
扫描二维码继续阅读
2019-08-31
分类
标签云