zoukankan      html  css  js  c++  java
  • UVa227

    //UVa227 - Puzzle
    #include<stdio.h>
    void swap(char *a, char *b){
    	char t = *a; *a = *b; *b = t;
    }
    int main(){
    	//freopen("date.in","r",stdin);
    	//freopen("date.out","w",stdout);
    	char s[6][6] = {0}, n;
    	int x1, y1, x2, y2;
    	int i, j, is = 0;
    	for(i = 0; i<5; i++){
    		for(j = 0; j<5; j++){
    			s[i][j] = getchar();
    			if(s[i][j] == ' ')x1 = x2 = i, y1 = y2 = j;
    		}
    		getchar();
    		//printf("%s
    ",s[i]);
    	}
    	while(scanf("%c",&n) && n != '0'){
    		switch(n){
    			case'A': x2 -= 1; break;
    			case'B': x2 += 1; break;
    			case'L': y2 -= 1; break;
    			case'R': y2 += 1; break;
    			default: is = 1;
    		}
    		swap(&s[x1][y1],&s[x2][y2]);
    		x1 = x2; y1 = y2;
    	}
    	if(is) printf("This puzzle has no final configuration.
    ");
    	else{
    		for(i = 0; i<5; i++)
    			printf("%s
    ",s[i]);
    	}
    	return 0;
    }
    /*
    Sample Input:
    TRGSJ
    XDOKI
    M VLN
    WPABE
    UQHCF
    ARRBBL0
    ABCDE
    FGHIJ
    KLMNO
    PQRS 
    TUVWX
    AAA
    LLLL0
    ABCDE
    FGHIJ
    KLMNO
    PQRS 
    TUVWX
    AAAAABBRRRLL0
    Z
    ------------------------
    Sample Output:
    Puzzle #1:
    T R G S J
    X O K L I
    M D V B N
    W P   A E
    U Q H C F
    
    Puzzle #2:
      A B C D
    F G H I E
    K L M N J
    P Q R S O
    T U V W X
    
    Puzzle #3:
    This puzzle has no final configuration.
    */
    

  • 相关阅读:
    十大Intellij IDEA快捷键
    多媒体播放API 生命周期束&简介
    Bitmap
    Activity
    Android中的Handler总结
    Bitmap2
    smartimageview和多线程
    Service
    微软面试题 博弈论 经典案例 (参考答案)
    ANR和消息机制
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444932.html
Copyright © 2011-2022 走看看