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;
    }
    
  • 相关阅读:
    c语言中sscanf()与sprintf()的使用
    oracle 12c 创建能用navicat 远程登录的帐号
    ubuntu14.0安装 oracle instant client(oracle 12c)
    【转】Xilinx FPGA ChipScope的ICON/ILA/VIO核使用
    ChipScope——ISE软件的抓波形操作
    【转】彻底掌握Quartus——基础篇
    千兆以太网(4):发送——ODDR原语和Wireshark抓包工具
    千兆以太网(3):发送——组建以太网心跳包
    千兆以太网(2):接收——包校验和数据筛选
    千兆以太网(1):接收——RGMII协议和IDDR原语
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11203986.html
Copyright © 2011-2022 走看看