求助大佬 感觉没啥问题只有WA50分

P1320 压缩技术(续集版)

GeorgeWang @ 2021-02-27 17:33:02

#include"stdio.h"
#include"string.h"
char str1[10000],N,s=1;
int a[10000][10000];
main()
{ 
  scanf("%s",str1);
  N=strlen(str1);

  for(int i=1;i<=N;i++)
    a[1][i]=str1[i-1];

  for(int i=2;i<=N;i++)
  {
    scanf("%s",str1);
    for(int j=1;j<=N;j++)
    a[i][j]=str1[j-1];
  }
   printf("%d ",N);
   if(a[1][1]=='1') printf("0 ");
  for(int i=1;i<=N;i++)   
  {
    for (int j=1;j<=N;j++)
    {
      if(i==N&&j==N) printf("%d",s);
      else if (j==N)
      {
        if(a[i][j]==a[i+1][1]){s++;}
        else {printf("%d ",s);s=1;}
       }
      else
       {
        if (a[i][j]==a[i][j+1]){s++;}
        else {printf("%d ",s);s=1;}
       }
    }   
  }
}

by yekgg @ 2021-02-27 17:47:03

strcat(text,str);

by yekgg @ 2021-02-27 17:47:59

for(i=0,sum=0,num='0';i<=strlen(text);i++)
        if(num==text[i])
            sum++;
        else
        {
            num=text[i];
            printf("%d ",sum);
            sum=1;
        }

by yekgg @ 2021-02-27 17:49:13

如果不行,最好捞一下


by yekgg @ 2021-02-27 17:52:36

主体就是这些了,我想会简化一些


by GeorgeWang @ 2021-02-27 21:34:26

@yekgg 感谢大佬!过了!


|