Poj3344 chessboard Dance (simulation)

Source: Internet
Author: User

Disgusting simulation. The Code is as long as Xiang. Just write it down ....

# Include <stdio. h> char ch [8] [9]; char Command [5]; int direction; int step; char DC [6]; int R; int C; int blank [8]; int directions [4] [2] = {-}, {0,-1 }}; char symbol [] = "^> v <"; void count_blank (void) {int COUNT = 0; int I = r; Int J = C; while (I> = 0 & I <8 & J> = 0 & J <8) {I + = directions [direction] [0]; J + = directions [direction] [1]; If (CH [I] [J] = '. ') {count ++; continue;} If (Direction = 0 | direction = 2) {Blank [I] = count;} else {B Lank [J] = count ;}}void move (void) {count_blank (); int I; int Ni; int offset; If (Direction = 0) {for (I = 0; I <r; I ++) {If (CH [I] [c] = '. ') {continue;} offset = Step-blank [I]; If (offset <= 0) {continue;} ni = I-offset; If (Ni <0) {continue;} ch [Ni] [c] = CH [I] [c];} ni = r-step; ni = Ni <0? 0: Ni; for (I = r; I> Ni; I --) {ch [I] [c] = '. ';} ch [r] [c] = '. '; ch [Ni] [c] =' ^ '; r = ni; return;} If (Direction = 2) {for (I = 7; I> r; I --) {If (CH [I] [c] = '. ') {continue;} offset = Step-blank [I]; If (offset <= 0) {continue;} ni = I + offset; If (Ni> 7) {continue;} ch [Ni] [c] = CH [I] [c];} ni = R + step; ni = Ni> 7? 7: Ni; for (I = r; I <Ni; I ++) {ch [I] [c] = '. ';} ch [r] [c] = '. '; ch [Ni] [c] = 'V'; r = ni; return;} If (Direction = 1) {for (I = 7; I> C; I --) {If (CH [r] [I] = '. ') {continue;} offset = Step-blank [I]; If (offset <= 0) {continue;} ni = I + offset; If (Ni> 7) {continue;} ch [r] [Ni] = CH [r] [I];} ni = C + step; ni = Ni> 7? 7: Ni; for (I = C; I <Ni; I ++) {ch [r] [I] = '. ';} ch [r] [c] = '. '; ch [r] [Ni] ='> '; C = ni; return;} If (Direction = 3) {for (I = 0; I <C; I ++) {If (CH [r] [I] = '. ') {continue;} offset = Step-blank [I]; If (offset <= 0) {continue;} ni = I-offset; If (Ni <0) {continue;} ch [r] [Ni] = CH [r] [I];} ni = C-step; ni = Ni <0? 0: Ni; for (I = C; I> Ni; I --) {ch [r] [I] = '. ';} ch [r] [c] = '. '; ch [r] [Ni] =' <'; C = ni; return ;}} void turn (void) {If (DC [0] = 'R ') {// rightdirection + = 1; Direction = direction = 4? 0: direction; ch [r] [c] = symbol [direction]; return;} If (DC [0] = 'l') {// leftdirection-= 1; direction = direction =-1? 3: direction; ch [r] [c] = symbol [direction]; return;} direction + = 2; // backdirection % = 4; ch [r] [c] = symbol [direction];} void print_table (void) {int I; for (I = 0; I <8; I ++) {printf ("% s \ n", CH [I]);} printf ("\ n");} int main (void) {int I, j; char TC; int find; while (1) {for (I = 0; I <8; I ++) {// read the scanf ("% s", CH [I]); if (CH [I] [0] = '-') {return 0 ;}} find = 0; for (I = 0; I <8; I ++) {// start point for (j = 0; j <8; j ++) {Tc = CH [I] [J]; if (TC = '<' | Tc = '>' | Tc = '^' | Tc = 'V') {r = I; C = J; find = 1; if (TC = '^') {direction = 0; break;} If (TC = '>') {direction = 1; break;} If (TC = 'V') {direction = 2; break;} If (TC = '<') {direction = 3; break ;}}} if (FIND) {break;} while (1) {// read scriptsscanf ("% s", command); If (command [0] = '#') {break;} If (command [0] = 'M') {scanf ("% d", & step); move ();} else {scanf ("% s", DC); turn () ;}} print_table ();} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.