zoukankan      html  css  js  c++  java
  • 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
    ", 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
    ", 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;
    }
    
  • 相关阅读:
    Echarts图表 相关技术点
    Jquery off() on() data()
    Js 正则表达式
    Java jar项目获取配置文件的项
    Java String.split 的坑,会忽略空值
    C# 工作流 状态机 门控制
    二维码SDK,高效率,高识别率,甩zxing,zbar几条街
    C#文本转语音,可导出在本地mp3或者wav文件
    api接口签名验证(MD5)
    C# 站点IP访问频率限制 针对单个站点的实现方法
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11203986.html
Copyright © 2011-2022 走看看