赞
踩
Fat brother and Maze are playing a kind of special (hentai) game on an NM board (N rows, M columns). At the beginning, there are NM coins in this board with two symbol “O” or “X”. Then they take turns to choose a grid with symbol “O” and change it into “X”. The game ends when all the symbols in the board are “X”, and the one who cannot play in his (her) turns loses the game. Fat brother and Maze like this kind of OOXX game very much and play it day and night. They don’t even need a little rest after each game!
Here’s the problem: Who will win the game if both use the best strategy? You can assume that Maze always goes first.
Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case contains two integers N and M indicate the size of the board. Then goes N line, each line with M character shows the state of the board.
1 <= T <=100, 1 <= n <=100, 1 <= m <=100
Output
For each case, output the case number first, and then output the winner’s name, either Fat brother or Maze. See the sample input and output for more details.
Sample Input
3
1 4
OXXX
2 4
OOXX
OOXX
1 2
XX
Sample Output
Case 1: Maze
Case 2: Fat brother
Case 3: Fat brother
思路:判断奇偶即可。
字符数组处理
#include<stdio.h> #include<iostream> using namespace std; char a[110]; int main() { int t; int ans=0; scanf("%d",&t); while(t--) { int n,m; int i; scanf("%d%d",&n,&m); getchar(); int cnt=0; for(i=1;i<=n*m;i++) {scanf("%c",&a[i]); if(a[i]=='O') cnt++; if(i%m==0) getchar(); } printf("Case %d: ",++ans); if(cnt%2==0) printf("Fat brother\n"); else printf("Maze\n"); } return 0; }
字符串数组
#include<stdio.h> char a[110][110]; int main() { int t; int ans=1; scanf("%d",&t); while(t--) { int i,n,m,j; int cnt=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%s",a[i]);//这里用i储存行。 for(i=0;i<n;i++) for(j=0;j<m;j++) if(a[i][j]=='O') cnt++; printf("Case %d: ",ans++); if(cnt%2==0) printf("Fat brother\n"); else printf("Maze\n"); } return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。