R3_C_Team Tic Tac Toe

Team Tic Tac Toe

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Farmer John owns 26 cows, which by happenstance all have names starting with different letters of the alphabet, so Farmer John typically refers to each cow using her first initial – a character in the range A…ZA…Z.

The cows have recently become fascinated by the game of tic-tac-toe, but since they don’t like the fact that only two cows can play at a time, they have invented a variant where multiple cows can play at once! Just like with regular tic-tac-toe, the game is played on a 3×33×3board, only instead of just Xs and Os, each square is marked with a single character in the range A…ZA…Z to indicate the initial of the cow who claims that square.

An example of a gameboard might be:

COWCOW

XXOXXO

ABCABC

The cows fill in each of the nine squares before they become confused about how to figure out who has won the game. Clearly, just like with regular tic-tac-toe, if any single cow has claimed an entire row, column, or diagonal, that cow could claim victory by herself. However, since the cows think this might not be likely given the larger number of players, they decide to allow cows to form teams of two, where a team of two cows can claim victory if any row, column, or diagonal consists only of characters belonging to the two cows on the team, and moreover if characters from both cows (not just one) are used in this row, column, or diagonal.

Please help the cows figure out how many individuals or two-cow teams can claim victory. Note that the same square on the game board might possibly be usable in several different claims to victory.

Input

The input consists of three lines, each of which is three characters in the range A…ZA…Z.

Output

Output should consist of two lines. On the first line, output the number of individual cows who can claim victory. On the second line, output the number of two-cow teams that could claim victory.

Example

input

Copy

COW
XXO
ABC

output

Copy

0
2

Note

In this example, no single cow can claim victory. However, if cows C and X team up, they can win via the C-X-C diagonal. Also, if cows X and O team up, they can win via the middle row.

题目大意

就是一个井字棋,但是不止两个玩家(一种字母代表一个玩家)。输出两个数字。第一个是正常的玩法,一个玩家的棋子占一行或者一列或者对角线,则算这个玩家胜利。第二个数字是若果两个玩家的棋子占一行或者一列或者对角线,就算这两个玩家胜利的情况(也就是两个玩家为一队的)。这里要注意的就是若两个玩家为一队,那么这一队要胜利的话,那一行(或者一列,或者对角线)要有两个玩家的棋子。一个玩家抱大腿是不可行的。

题目分析

若是了解了题意,这道题就是一道很简单的模拟题了。不过是代码有点长。之前就是没留意到抱大腿的情况,导致wa了好几发。因为最多只有九个玩家,任选两个玩家来匹配也不过是81种情况。怎么模拟都行。

两种玩家的模拟就是统计一行(或者一列,对角线)里,两个玩家的棋子的个数,如果和为3,且都大于0的话就说明这是一种胜利情况,答案加一即可。这里的代码是比赛的时候写的。代码有点丑,分开了两个judege函数。其实是不用的(主要是比赛的时候懒得封装,直接复制粘贴了一波)。

代码

#include <cstdio>
using namespace std;
char map[3][3];
bool judge(char a, char b){

  for(int i = 0; i < 3; i++){
    int x = 0, y = 0;
    for(int j = 0; j < 3; j++){
      if(map[i][j] == a)
        x++;
      if(map[i][j] == b)
        y++;
    }
    if(x + y == 3 && x && y)
      return true;
  }


  for(int i = 0; i < 3; i++){
    int x = 0, y = 0;
    for(int j = 0; j < 3; j++){
      if(map[j][i] == a)
        x++;
      if(map[j][i] == b)
        y++;
    }
    if(x + y == 3 && x && y)
      return true;
  }


  int x = 0, y = 0;
  for(int i = 0; i < 3; i++){
    if(map[i][i] == a)
      x++;
    if(map[i][i] == b)
      y++;
  }
  if(x + y == 3 && x && y)
    return true;

  x = 0; y = 0;
  for(int i = 2; i >= 0; i--){
    if(map[i][i] == a)
      x++;
    if(map[i][i] == b)
      y++;
  }
  if(x + y == 3 && x && y)
    return true;

  return false;
}

bool judge2(char a){
    for(int i = 0; i < 3; i++){
      int x = 0;
      for(int j = 0; j < 3; j++){
        if(map[i][j] == a)
          x++;
      }
      if(x == 3)
        return true;
    }


    for(int i = 0; i < 3; i++){
      int x = 0;
      for(int j = 0; j < 3; j++){
        if(map[j][i] == a)
          x++;
      }
      if(x == 3)
        return true;
    }


    int x = 0;
    for(int i = 0; i < 3; i++){
      if(map[i][i] == a)
        x++;
    }
    if(x == 3)
      return true;

    x = 0;
    for(int i = 2; i >= 0; i--){
      if(map[i][i] == a)
        x++;
    }
    if(x == 3)
      return true;

    return false;
}
int main(int argc, char const *argv[]) {
  char t[9];
  int cnt = 0;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      map[i][j] = getchar();

      bool flag = true;
      for(int k = 0; k < cnt; k++)
        if(t[k] == map[i][j])
          flag = false;
      if(flag)
        t[cnt++] = map[i][j];
    }
    getchar();
  }
  int ans1 = 0, ans2 = 0;
  for(int i = 0; i < cnt; i++)
    if(judge2(t[i]))
      ans1++;
  for(int i = 0; i < cnt; i++)
    for(int j = i + 1; j < cnt; j++){
      if(judge(t[i], t[j])){
        ans2++;
      }
    }
  printf("%d\n%d\n", ans1, ans2);
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值