• 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#之委托总结
    shell编程基础
    专家是什么?我真的想知道(转)
    linux sed
    判断一个脚本中的变量是否为空(转)
    JAVA Stack栈和Heap堆的区别(转)
    CMD获取当前目录的绝对路径 (转)
    RTP协议分析
    VS2010旗舰版安装图解
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11203986.html
Copyright © 2020-2023  润新知