laoguo1112359 @ 2023-05-27 17:18:19
#include <bits/stdc++.h>
using namespace std;
char ch[100];
char sum[5][400];
int i;
int main()
{
int n;
scanf("%d",&n);
scanf("%s",ch);
char* s = ch;
while(*s != '\0')
{
switch(*s)
{
case '0':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
sum[2][i]=sum[2][i+2]='X';sum[2][i+1]='.';
sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '1':
sum[0][i]=sum[0][i+1]='.';sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]=sum[2][i+1]='.';sum[2][i+2]='X';
sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '2':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]='X';sum[3][i+1]=sum[3][i+2]='.';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '3':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '4':
sum[0][i]=sum[0][i+2]='X';sum[0][i+1]='.';
sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '5':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='X';sum[1][i+2]='.';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]=sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '6':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='X';sum[1][i+2]='.';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '7':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]=sum[2][i+1]='.';sum[2][i+2]='X';
sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '8':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
case '9':
sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]=sum[3][i+2]='X';
sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
break;
}
if(*(s+1)!='\0')
{
sum[0][i+3]=sum[1][i+3]=sum[2][i+3]=sum[3][i+3]=sum[4][i+3]='.';
}
i+=4;
s++;
}
for(int j=0;j<5;j++)
{
for(int k=0;k<4*n;k++)
cout<<sum[j][k];
cout<<endl;
}
return 0;
}
/*
0 1 2 3 4 5 6 7 8 9
XXX . ..X . XXX . XXX . X.X . XXX . XXX . XXX . XXX . XXX
X.X . ..X . ..X . ..X . X.X . X.. . X.. . ..X . X.X . X.X
X.X . ..X . XXX . XXX . XXX . XXX . XXX . ..X . XXX . XXX
X.X . ..X . X.. . ..X . ..X . ..X . X.X . ..X . X.X . ..X
XXX . ..X . XXX . XXX . ..X . XXX . XXX . ..X . XXX . XXX
*/
by SCAR_L @ 2023-05-27 17:28:19
@laoguo1112359 NB,写了这么多行
by SCAR_L @ 2023-05-27 17:43:34
@laoguo1112359 您好,您代码的数字5 6 9部分有问题
by SCAR_L @ 2023-05-27 17:47:02
@laoguo1112359 还有,您输出部分 k 的终止条件应为k < 4*n-1
。
by SCAR_L @ 2023-05-27 17:50:29
您可以参照一下:
by SCAR_L @ 2023-05-27 18:05:21
您也可以参考我的代码(其实只是在您的代码上改了一下):
#include <bits/stdc++.h>
using namespace std;
char ch[100];
char sum[5][400];
int i;
int main()
{
int n;
scanf("%d", &n);
scanf("%s", ch);
char* s = ch;
while(*s != '\0')
{
switch(*s)
{
case '0':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='.';sum[2][i+2]='X';
sum[3][i]='X';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '1':
sum[0][i]='.';sum[0][i+1]='.';sum[0][i+2]='X';
sum[1][i]='.';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='.';sum[2][i+1]='.';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='.';sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '2':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='.';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='X';sum[3][i+1]='.';sum[3][i+2]='.';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '3':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='.';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '4':
sum[0][i]='X';sum[0][i+1]='.';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='.';sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '5':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='.';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '6':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='.';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='X';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '7':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='.';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='.';sum[2][i+1]='.';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='.';sum[4][i+1]='.';sum[4][i+2]='X';
break;
case '8':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='X';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
case '9':
sum[0][i]='X';sum[0][i+1]='X';sum[0][i+2]='X';
sum[1][i]='X';sum[1][i+1]='.';sum[1][i+2]='X';
sum[2][i]='X';sum[2][i+1]='X';sum[2][i+2]='X';
sum[3][i]='.';sum[3][i+1]='.';sum[3][i+2]='X';
sum[4][i]='X';sum[4][i+1]='X';sum[4][i+2]='X';
break;
}
if(*(s+1)!='\0')sum[0][i+3]=sum[1][i+3]=sum[2][i+3]=sum[3][i+3]=sum[4][i+3]='.';
i += 4;
s++;
}
for(int j = 0; j < 5; j++)
{
for(int k = 0; k < 4*n-1; k++)
cout << sum[j][k];
cout << endl;
}
return 0;
}
by SCAR_L @ 2023-05-27 20:26:21
@laoguo1112359 看我写的这么辛苦,给个关注呗,球球了
by laoguo1112359 @ 2023-05-28 06:27:13
@SCAR_L 非常感谢,还是粗心了,敲完后一看大差不差就提交了,我的5、6、9的第二行和第四行基本都是复制的5的代码,所以就一同出错了
by laoguo1112359 @ 2023-05-28 06:28:56
@SCAR_L 我发现终止条件不改也能过,不改是不是会越界啊?
by laoguo1112359 @ 2023-05-28 06:29:46
@SCAR_L 关注了,感谢佬的答疑解惑
by SCAR_L @ 2023-05-28 08:41:21
@laoguo1112359 谢谢关注。终止条件因为你 a 数组最后一列用的是(n-1)*i+2
而不是n*4
,所以还是建议改一下。能过应该和luogu的评测机有关系。