标签:== color i++ return code get 代码 解决 style
一想到这个题目AC的情景啊,那个激动兴奋的,交了几十遍。。。。各种错误,真的是说不出来的感觉。但是收获也不少。在此分享。
code:
#include<stdio.h> #include<string.h> //#define LOCAL char puzzle[35]; // the function to change position. // A is the movement. // B is the array of Puzzle. int chposition(char a, char b[]) { char c(‘0‘); char* temp = strchr(b, ‘ ‘); // return 1 when occurs the wrong move or out of the range. if( a == ‘A‘) { if(temp-5 < b) return 1; c = *(temp-5); *(temp-5) = *temp; *temp = c; temp = temp - 5;} else if( a == ‘B‘) { if(temp+5 > b+24) return 1; c = *(temp+5); *(temp+5) = *temp; *temp = c; temp = temp + 5; } else if( a == ‘L‘) { if((temp-b)%5-1 < 0) return 1; c = *(temp-1); *(temp-1) = *temp; *temp = c; temp = temp - 1; } else if( a == ‘R‘) { if((temp-b)%5+1 > 4 ) return 1; c = *(temp+1); *(temp+1) = *temp; *temp = c; temp = temp + 1;} else return 1; return 0; } int main() { //overload the printf and scanf. #ifdef LOCAL freopen("data.in", "r", stdin); freopen("data.out", "w", stdout); #endif int count = 0; int first = 1; while(true) { memset(puzzle,0,35); count++; char c = getchar(); //if ( c == ‘\n‘) c = getchar(); //ignore the ‘\n‘ if( c == ‘Z‘) break; //‘Z‘ the signal of the end. else puzzle[0] = c; int i = 1; for(; i < 25; i++) { puzzle[i] = getchar(); if(puzzle[i] == ‘\n‘) i--; } int flag = 0; int taq(0); while( (c = getchar()) && c != ‘0‘) { if(c == ‘\n‘)continue; flag = chposition(c, puzzle); if(flag == 1) taq = 1; } getchar(); if( first == 1) { first = 0; } else{ putchar(‘\n‘); } printf("Puzzle #%d:\n",count); if(taq) printf("This puzzle has no final configuration.\n"); else { for(i = 0; i <25; i++) { if((i+1)%5 == 0)printf("%c\n", puzzle[i]); else { printf("%c ", puzzle[i]); } } } } return 0; }
标签:== color i++ return code get 代码 解决 style
原文地址:https://www.cnblogs.com/dreamworldclark/p/9420319.html