Elizabeththh @ 2024-11-03 10:23:12
#include <stdio.h>
int main()
{
int n = 0;
scanf("%d",&n);
int zip[40000] = {0};
for(int i = 0;getchar() != '\n';i++)
{
scanf("%d",&zip[i]);
}
int sum = 0;
int i = 0,width = 0;
while(sum != n*n)
{
if(i % 2 == 0)
{
for(int j = 0;j < zip[i];j++)
{
if(width < 7)
{
printf("0");
width++;
}
else
{
printf("\n0");
width = 1;
}
}
sum+=zip[i];
i++;
}
else
{
for(int j = 0;j < zip[i];j++)
{
if(width < 7)
{
printf("1");
width++;
}
else
{
printf("\n1");
width = 1;
}
}
sum+=zip[i];
i++;
}
}
}
by Elizabeththh @ 2024-11-03 11:21:42
@Licak 如果不考虑读入问题且假设读入之后已经得到了一个存储压缩码的数组。设置一个变量sum,判断是否已经处理完压缩码(显然压缩码的和为nn)。设置入口while循环,用嵌套for循环依次处理每一个压缩码,用if判断奇偶,偶数打印0,奇数打印1。每一次处理完压缩码之后,把压缩码递增到sum中,直至sum等于nn
且每次打印时都用width和7的比较判断是否需要换行
by Elizabeththh @ 2024-11-03 11:22:10
@youyew2007 好的,谢谢,我改一下试试
by Elizabeththh @ 2024-11-03 11:30:35
@youyew2007 改完之后不TLE了,可是全是WA......
但给的测试用例,在VSCODE上运行仍然是正确的,可能还是读入问题?
by go_your_a_head @ 2024-11-03 12:29:59
@Elizabeththh 7???为什么要跟7比较,不应该是n吗。
by Elizabeththh @ 2024-11-03 12:58:40
@Licak 啊我傻了,用特例思考的,忘记改过来了,谢谢大佬!!