📄 2182591_pe.c
字号:
# include <stdio.h>
# include <string.h>
# define C 45
void input()
{
int t, i, j, p, z;
char tu[10][10];
int tmp, con, P, J;
scanf("%d",&t);
z = 0;
for(i = 1; i <= t; i++)
{
for(j = 0; j < 9; j++)
{
scanf("%s",tu[j]);
for(p = 0; p < 9; p++)
if(tu[j][p]=='0')
z++;
}
printf("Scenario #%d:\n",i);
while(z)
{
for(j = 0; j < 9; j++)
{
tmp = 0;
for(p = 0; p < 9; p++)
if(tu[j][p]=='0')
{
tmp++;
P = p;
}
if(tmp==1)
{
con = C;
for(p = 0; p < 9; p++)
con -= tu[j][p]-'0';
tu[j][P] = con + '0';
z--;
}
}
for(p = 0; p < 9; p++)
{
tmp = 0;
for(j = 0; j < 9; j++)
if(tu[j][p]=='0')
{
tmp++;
J = j;
}
if(tmp==1)
{
con = C;
for(j = 0; j < 9; j++)
con -= tu[j][p]-'0';
tu[J][p] = con + '0';
z--;
}
}
for(j = 0; j < 9; j+=3)
{
for(p = 0; p < 9; p+=3)
{
tmp = 0;con = C;
if(tu[j][p+0]=='0') {tmp++;J = j;P = p+0;} else con -= tu[j][p+0] - '0';
if(tu[j][p+1]=='0') {tmp++;J = j;P = p+1;} else con -= tu[j][p+1] - '0';
if(tu[j][p+2]=='0') {tmp++;J = j;P = p+2;} else con -= tu[j][p+2] - '0';
if(tu[j+1][p]=='0') {tmp++;J = j+1;P = p;} else con -= tu[j+1][p] - '0';
if(tu[j+1][p+1]=='0') {tmp++;J = j+1;P = p+1;} else con -= tu[j+1][p+1] - '0';
if(tu[j+1][p+2]=='0') {tmp++;J = j+1;P = p+2;} else con -= tu[j+1][p+2] - '0';
if(tu[j+2][p+0]=='0') {tmp++;J = j+2;P = p+0;} else con -= tu[j+2][p+0] - '0';
if(tu[j+2][p+1]=='0') {tmp++;J = j+2;P = p+1;} else con -= tu[j+2][p+1] - '0';
if(tu[j+2][p+2]=='0') {tmp++;J = j+2;P = p+2;} else con -= tu[j+2][p+2] - '0';
if(tmp==1)
{
tu[J][P] = con + '0';
z--;
}
}
}
}
for(j = 0; j < 9; j++)
puts(tu[j]);
}
}
int main()
{
input();
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -