PAT A1042 Shuffling Machine
自己思路,没通过
#include <cstdio>
#define N 54
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int start[N + 1] = {0}, end[N + 1] = {0}, sequence[N + 1] = {0};
for(int i = 1; i < N + 1; i++) {//初始化牌的编号
start[i] = i+1;
}
int n;
scanf("%d", &n);//输入操作的次数
for(int i = 1; i < N + 1; i++) {//输入每个位置上的牌在操作后的位置
int n;
scanf("%d", &sequence[i]);
}
/*for(int i = 1; i < N; i++) {
printf("%d\n", sequence[i]);
}*/
for(int i = 0; i < n; i++) {//执行n次操作
for(int i = 1; i < N + 1; i++) {
end[sequence[i]] = start[i];
}
for(int i = 1; i < N + 1; i++) {
start[i] = end[i];
}
}
/*for(int i = 1; i < N + 1; i++) {
printf("%d\n", end[i]);
}
*/
for(int i = 1; i < N; i++) {
//printf("%d---", end[i]);
if(i != N) {
if(end[i] / 13 == 0) {
if(end[i] % 13 == 0) {
printf("S13 ");
} else {
printf("S%d ", end[i] % 13);
}
} else if(end[i] / 13 == 1) {
if(end[i] % 13 == 0) {
printf("H13 ");
} else {
printf("H%d ", end[i] % 13);
}
} else if(end[i] / 13 == 2) {
if(end[i] % 13 == 0) {
printf("C13 ");
} else {
printf("C%d ", end[i] % 13);
}
} else if(end[i] / 13 == 3) {
if(end[i] % 13 == 0) {
printf("D13 ");
} else {
printf("D%d ", end[i] % 13);
}
} else if(end[i] / 13 == 4) {
printf("J%d ", end[i] % 13);
}
} else {
if(end[i] / 13 == 0) {
if(end[i] % 13 == 0) {
printf("S13");
} else {
printf("S%d", end[i] % 13);
}
} else if(end[i] / 13 == 1) {
if(end[i] % 13 == 0) {
printf("H13");
} else {
printf("H%d", end[i] % 13);
}
} else if(end[i] / 13 == 2) {
if(end[i] % 13 == 0) {
printf("C13");
} else {
printf("C%d", end[i] % 13);
}
} else if(end[i] / 13 == 3) {
if(end[i] % 13 == 0) {
printf("D13");
} else {
printf("D%d", end[i] % 13);
}
} else if(end[i] / 13 == 4) {
printf("J%d", end[i] % 13);
}
}
}
return 0;
}
AC
#include <cstdio>
const int N = 54;
char mp[5] = {'S', 'H', 'C', 'D', 'J'};
int start[N+1], end[N+1], next[N+1];
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int K;
scanf("%d", &K);
for(int i = 1; i <= N; i++) {
start[i] = i;
}
for(int i = 1; i <= N; i++) {
scanf("%d", &next[i]);
}
for(int step = 0; step < K; step++) {
for(int i = 1; i <= N; i++) {
end[next[i]] = start[i];
}
for(int i = 1; i <= N; i++) {
start[i] = end[i];
}
}
for(int i = 1; i <= N; i++) {
if(i != 1) printf(" ");
start[i]--;
printf("%c%d", mp[start[i] / 13], start[i] % 13 + 2);
}
return 0;
}
PAT A1042 Shuffling Machine的更多相关文章
- PAT甲级——A1042 Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- PAT 1042. Shuffling Machine (20)
1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...
- A1042. Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- PAT 1042 Shuffling Machine[难]
1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...
- A1042 Shuffling Machine (20)
1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...
- pat 1042 Shuffling Machine(20 分)
1042 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Bec ...
- PAT 1042 Shuffling Machine (20 分)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 1042 Shuffling Machine
#include <cstdio> #include <cstdlib> #include <vector> using namespace std; ] = {' ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
随机推荐
- Mac下Tomcat安装&配置&80默认端口设置
序言: 在学习Tomcat时, 部署虚拟服务主机时,遇到了无响应的情况.原以为是应为Tomcat默认端口8080在调整至(进行端口转发设置)默认端口80会和Mac自带Apache起冲突.但是也有同学使 ...
- DataTable转List,DataTable转为Model对象帮助类
DataTable转List,DataTable转为Model对象帮助类 public class ModelConvertHelper<T> where T : new() { publ ...
- python itern机制的
这些变量很可能在许多程序中使用. 通过池化这些对象,Python可以防止对一致使用的对象进行内存分配调用. 1.介于数字-5和256之间的整数 2.字符串仅包含字母.数字或下划线
- solr安装记录
[root@localhost bin]# ./solr start -force*** [WARN] *** Your open file limit is currently 1024. It ...
- C#_类
1:访问修饰符 访问修饰符可以定义应用程序中类成员的作用域.和C++有一些不同,下面说明一下: public:访问不受限制,public成员可以被任何其他类访问. private:访问只限于包含该成员 ...
- Innodb内存结构
聚集索引与非聚集索引: 聚集索引:主键,有序,存储顺序与内存一致 非聚集索引:非主键,无序 聚集索引在叶子节点存储的是表中的数据 非聚集索引在叶子节点存储的是主键和索引列 使用非聚集索引查询出数据 ...
- openapi and light-4j
light-4j项目支持openapi规范,本文介绍一下参照相关demo做的上传功能. openapi.yaml,按照规范编写内容,/openapi/swagger可以查看对应的swagger页面,A ...
- mac 安装laravel
安装laravel之前先安装composer 使用 curl 指令下载: curl -sS https://getcomposer.org/installer | php 或是沒有安裝 curl ,也 ...
- 提高组刷题营 DAY 2
1.滞空(jump/1s/64M) #include<bits/stdc++.h> using namespace std; typedef long long LL; ; inline ...
- vue-图片预览,查看大图
[前言] 在 vue 项目中经常碰到图片预览需求,也就是点击小图查看大图.也有一些这样的第三方插件,如 vue-preview 等.但使用起来感觉版本经常变,而且有时 UI 需要在预览页面上加更多的东 ...