1042

piccolo
同一题目5秒内只能提交1次
1042. Shuffling Machine (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

S1, S2, …, S13, H1, H2, …, H13, C1, C2, …, C13, D1, D2, …, D13, J1, J2

where “S” stands for “Spade”, “H” for “Heart”, “C” for “Club”, “D” for “Diamond”, and “J” for “Joker”. A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer K (<= 20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.
Sample Input:

2
36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47

Sample Output:

S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5

:start储存变换前顺序,end储存变化后顺序

#include <iostream>

using namespace std;

int start[55];
int endd[55];
int seq[55];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1;i<55;i++)
    {
        scanf("%d", &seq[i]);
        endd[i] = i;
    }

    for(int i=0;i<n;i++)
    {
        for(int j=1;j<55;j++)
            start[j] = endd[j];
        for(int k=1;k<55;k++)
            endd[seq[k]] = start[k];
    }

    char c[5] = {'S','H','C','D','J'};
    for(int i=1;i<55;i++)
    {
        printf("%c%d", c[(endd[i]-1)/13], (endd[i]-1)%13+1);
        if(i!=54)
            printf(" ");
    }

    return 0;
}
<think>嗯,用户想找一本通1042相关的IT内容或编程题解。首先,我需要确认“一本通1042”具体指的是哪本书或者哪个题库的题目。通常“一本通”可能指的是《信息学奥赛一本通》这本书,里面有很多编程题目,编号可能对应不同的问题。 接下来,我需要回忆或查找相关资料。根据用户提供的引用,比如引用[3]提到了信息学奥赛一本通在线评测系统,里面有3313题的代码示例。不过用户的问题是关于1042号的,我需要确定这个题目的内容。 可能用户提到的“一本通1042”是某个特定的编程题目,比如可能是数组操作、循环结构或者算法题。比如,引用[5]里提到了一本通的1329细胞问题,使用广度优先搜索。可能1042题也是类似的算法题,但具体题目内容需要进一步确认。 由于用户提供的引用中没有直接提到1042题,可能需要推测。比如,查找常见的《信息学奥赛一本通》题目,1042可能涉及字符处理、字符串操作或者数学问题。例如,可能是统计字符出现次数,或者计算某个数学问题。 用户可能需要题解、解题思路或者示例代码。根据引用中的示例代码,比如引用[3]中的代码结构,可以推测可能需要用C++来解答。因此,在回答时应该提供清晰的解题步骤,代码示例,并确保符合LaTeX格式的要求。 另外,用户要求生成相关问题,可能需要围绕该题目的应用、变体或相关算法来提问。比如,如果题目是关于字符串处理,相关问题可能涉及不同的处理方法或优化技巧。 需要确保回答结构清晰,分步骤解释,同时引用提供的资料。比如,引用[3]中的代码结构可以作为参考,但需要确认是否适用于1042题。如果无法直接找到1042题的具体内容,可能需要提示用户补充题目描述,或者根据常见的一本通题目进行合理推测。 最后,确保使用正确的中文表达,避免术语错误,并检查LaTeX格式是否正确,比如变量用$...$包裹,独立公式用$$...$$。</think>### 一本通 1042 相关编程问题解析 根据《信息学奥赛一本通》的编号规则,**1042**可能对应**字符统计类问题**或**基础算法题**。以下是基于常见题型的推测与解析: --- #### **假设题目:统计特定字符出现次数** **题目描述**:输入一行字符,统计其中数字、字母、空格和其他字符的数量。 --- #### **解题思路** 1. **输入处理**:读取字符串或逐个字符输入。 2. **分类判断**: - 使用条件语句判断字符类型(数字、字母、空格等)。 3. **计数统计**:通过变量记录每类字符的数量。 --- #### **C++代码实现** ```cpp #include <iostream> #include <cctype> // 使用字符分类函数 using namespace std; int main() { char ch; int digit = 0, alpha = 0, space = 0, other = 0; while ((ch = getchar()) != '\n') { if (isdigit(ch)) digit++; else if (isalpha(ch)) alpha++; else if (isspace(ch)) space++; else other++; } cout << "数字:" << digit << endl << "字母:" << alpha << endl << "空格:" << space << endl << "其他:" << other << endl; return 0; } ``` **代码说明**: - 使用`getchar()`逐字符读取输入,直到换行符。 - 通过`<cctype>`库的`isdigit`、`isalpha`等函数判断字符类型。 - 时间复杂度为$O(n)$,适用于长字符串[^3]。 --- #### **相关问题** 1. 如何优化该代码以处理超长输入(例如文件流)? 2. 如果需统计中文字符,代码需要如何修改? 3. 如何用Python实现类似功能? --- #### **参考扩展** - **字符串处理**:类似题目可见于一本通的数组和字符串章节,如字符替换、大小写转换等[^3]。 - **算法应用**:若涉及更复杂统计(如词频),可能需要哈希表(如`unordered_map`)[^5]。 若需更准确的题解,请补充题目描述或确认具体编号对应的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值