显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int m,n,k,l;
string s1,s2,s3;
int ans1,ans2;
int a[4][4];
int b[27];
void work1();
void work2();
bool use[27][9];
int cnt;
bool pd(int m,int n)
{ for (int i=1;i<=cnt;i++)
if (use[m][i]&&use[n][i]) return false;
return true;
}
int main()
{ freopen("tttt_bronze_18open.in","r",stdin);
freopen("tttt_bronze_18open.out","w",stdout);
getline(cin,s1);
getline(cin,s2);
getline(cin,s3);
for (int i=0;i<=2;i++)
{ a[1][i+1]=s1[i]-'A'+1;
a[2][i+1]=s2[i]-'A'+1;
a[3][i+1]=s3[i]-'A'+1;
}
work1();
work2();
printf("%d\n%d",ans1,ans2);
return 0;
}
void work1()
{ bool use[27];
memset(use,0,sizeof(use));
for (int i=1;i<=3;i++)
{ memset(b,0,sizeof(b));
for (int j=1;j<=3;j++)
b[a[i][j]]++;
for (int j=1;j<=26;j++)
if (b[j]==3&&!use[j]) {use[j]=true;ans1++;} }//判断横行
for (int i=1;i<=3;i++)
{ memset(b,0,sizeof(b));
for (int j=1;j<=3;j++)
b[a[j][i]]++;
for (int j=1;j<=26;j++)
if (b[j]==3&&!use[j]) {use[j]=true;ans1++;}}//判断竖行
memset(b,0,sizeof(b));
b[a[1][1]]++;b[a[2][2]]++;b[a[3][3]]++;
for (int i=1;i<=26;i++)
if (b[i]==3&&!use[i]) {use[i]=true;ans1++;}//判断斜行
memset(b,0,sizeof(b));
b[a[3][1]]++;b[a[2][2]]++;b[a[1][3]]++;
for (int i=1;i<=26;i++)
if (b[i]==3&&!use[i]) {use[i]=true;ans1++;} //判断斜行
}
void work2()
{ for (int i=1;i<=3;i++)
{ memset(b,0,sizeof(b));
for (int j=1;j<=3;j++)
b[a[i][j]]++;
for (int j=1;j<=26;j++)
for (int k=i;k<=26;k++)
if (b[j]+b[k]==3&&b[j]!=3&&b[k]!=3)
if (pd(j,k)) {cnt++;use[j][cnt]=true;use[k][cnt]=true;ans2++;}
}//判断横行
for (int i=1;i<=3;i++)
{ memset(b,0,sizeof(b));
for (int j=1;j<=3;j++)
b[a[j][i]]++;
for (int j=1;j<=26;j++)
for (int k=j;k<=26;k++)
if (b[j]+b[k]==3&&b[j]!=3&&b[k]!=3)
if (pd(j,k)) {cnt++;use[j][cnt]=true;use[k][cnt]=true;ans2++;}//判断竖行
}
memset(b,0,sizeof(b));
b[a[1][1]]++;b[a[2][2]]++;b[a[3][3]]++;
for (int j=1;j<=26;j++)
for (int k=j;k<=26;k++)
if (b[j]+b[k]==3&&b[j]!=3&&b[k]!=3)
if (pd(j,k)) {cnt++;use[j][cnt]=true;use[k][cnt]=true;ans2++;}
memset(b,0,sizeof(b));
b[a[3][1]]++;b[a[2][2]]++;b[a[1][3]]++;
for (int j=1;j<=26;j++)
for (int k=j;k<=26;k++)
if (b[j]+b[k]==3&&b[j]!=3&&b[k]!=3)
if (pd(j,k)) {cnt++;use[j][cnt]=true;use[k][cnt]=true;ans2++;}//判断斜行
}