標籤:style blog http color os io for ar 2014
1 /* 2 * Main.c 3 * E12-數組-12. 簡易連連看 4 * Created on: 2014年8月22日 5 * Author: Boomkeeper 6 ********測試通過********* 7 */ 8 9 #include <stdio.h>10 #include <stdlib.h>11 12 int main(void){13 14 int x1,y1,x2,y2;15 int i,j,k;16 int N;//題目中的N17 char array[10][10];18 int count=0;//計次匹配錯誤的次數19 int m=0;//玩家輸入的次數20 int letterLeft;//盤面中剩餘的字母個數,當減少到0時,則勝利21 22 scanf("%i",&N);23 getchar();24 25 letterLeft=2*N*2*N;26 27 for(i=0;i<(2*N);i++)28 for(j=0;j<(2*N);j++){29 array[i][j]=getchar();30 getchar();31 }32 33 scanf("%d",&m);34 getchar();35 36 for(i=0;i<m;i++){37 scanf("%d %d %d %d",&x1,&y1,&x2,&y2);38 39 //匹配成功,則將兩個符號消為“*”40 if((array[x1-1][y1-1]==array[x2-1][y2-1]) &&41 (array[x1-1][y1-1]<=‘Z‘ && array[x1-1][y1-1]>=‘A‘)){42 array[x1-1][y1-1]=‘*‘;43 array[x2-1][y2-1]=‘*‘;44 letterLeft=letterLeft-2;45 46 } else{47 printf("Uh-oh\n");48 count++;49 continue;50 }51 //若匹配錯誤達到3次,則輸出“Game Over”並結束遊戲52 if(count==3){53 printf("Game Over\n");54 exit(0);55 }56 //當全部符號匹配成功,則輸出“Congratulations!”,然後結束遊戲57 if(letterLeft==0){58 printf("Congratulations!\n");59 exit(0);60 }61 //輸出盤面62 for(j=0;j<2*N;j++){63 for(k=0;k<2*N-1;k++)64 printf("%c ",array[j][k]);65 printf("%c\n",array[j][2*N-1]);66 }67 68 }69 70 return 0;71 }
剛看到這個題目頭都大了,簡直就是一篇短文閱讀理解,那麼多字...一下子就沒了耐心。
但最後發現,它比“數組-11. 猴子選大王”還是簡單多了,因為沒有涉及很高深的數學問題,只要耐住性子,還是做了出來。
只是讀題目就讀了三四遍,測試了幾十遍...這要是在考試中...%>_<% %>_<%
題目連結:
http://pat.zju.edu.cn/contests/basic-programming/%E6%95%B0%E7%BB%84-12
.
數組-12. 簡易連連看