题目:https://www.jisuanke.com/contest/965
B:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int t;
char a[3][3];
scanf("%d",&t);
while(t--){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cin>>a[i][j];
}
}
int flag0=0;
for(int i=0;i<3;i++){
if(a[i][0]==a[i][1]&&a[i][1]==a[i][2]&&a[i][0]!='.'){
cout<<a[i][0]<<endl;
flag0=1;
break;
}
if(a[0][i]==a[1][i]&&a[1][i]==a[2][i]&&a[0][i]!='.'){
cout<<a[0][i]<<endl;
flag0=1;
break;
}
}
if(flag0==1) continue;
if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[0][0]!='.'){
cout<<a[0][0]<<endl;
continue;
}
if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&a[0][2]!='.'){
cout<<a[0][2]<<endl;
continue;
}
cout<<"ongoing"<<endl;
}
return 0;
}
I:
#include<bits/stdc++.h>
using namespace std;
char a[37][37];
int i,j,n,di,dj,l,r,up,down;
void dfs(){
if(down&&a[i+2][j]=='#'&&a[i-2][j]==0||up&&a[i-2][j]=='#'&&a[i+2][j]==0||l&&a[i][j-2]=='#'&&a[i][j+2]==0||r&&a[i][j+2]=='#'&&a[i][j-2]==0){
a[i][j]='#';return ;
}
if(r && (j>=n-1||a[i][j+2]=='#')){
di=1;dj=0;r=0;down=1;
}
else if(down && (i>=n-1||a[i+2][j]=='#')){
di=0;dj=-1;down=0;l=1;
}
else if(l && (j<=0||a[i][j-2]=='#')){
di=-1;dj=0;l=0;up=1;
}
else if(up && (i<=0||a[i-2][j]=='#')){
di=0;dj=1;up=0;r=1;
}
a[i][j]='#';
if(a[i][j+2]=='#'&&a[i][j-2]=='#'&&a[i+2][j]=='#'&&a[i-2][j]=='#')
return;
i+=di;j+=dj;
dfs();
}
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
i=0;j=0;di=0;dj=1;
l=0;r=1;up=0;down=0;
scanf("%d",&n);
if(n==1){
cout<<"#"<<endl;
continue;
}
if(n==2){
cout<<"##"<<endl<<" #"<<endl;
continue;
}
if(n==3){
cout<<"###"<<endl<<" #"<<endl<<"###"<<endl;
continue;
}
dfs();
for(int ii=0;ii<n;ii++){
for(int jj=0;jj<n;jj++){
if(a[ii][jj]!='#')
cout<<" ";
else cout<<a[ii][jj];
}
cout<<endl;
}
}
return 0;
}