为什么会超时?

P1320 压缩技术(续集版)

xxfdzl @ 2017-04-19 13:26:15

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int r=0,p=0;
    char s[201],q;
    gets(s);
    int l=strlen(s);
    int n=l*(l-1);
    cout<<l<<" ";
    for(int i=0;i<l;++i)
    {
        if(s[i]-'0'==r)
          p++;
        else
          {
              i--;
               cout<<p<<" ";
               p=0;
               if(r==0)
                 r++;
              else
                r--;
          }
    }
    for(int i=1;i<=n;++i)
    {
      cin>>q;
        if(q-'0'==r)
          p++;
        else
          {
              if(i!=n)
               cout<<p<<" ";
              else
                     cout<<p;
               p=1;
               if(r==0)
                 r++;
              else
                r--;
          }
    }
    cout<<p;
    return 0;
}

by xxfdzl @ 2017-04-19 13:27:06

@maruijie


by xxfdzl @ 2017-04-19 13:27:51

@ maruijie


by xxfdzl @ 2017-04-19 13:28:31

@maruijie


by bestcow @ 2017-04-25 22:34:08

我们你一个问题,你这么多的for语句干嘛,精简程序,省去不必要的、重复的部分,这个你要动动你那不开窍的小脑袋了~~


by 4kilometers @ 2017-10-16 20:06:41

因为你太铯了啊


|