| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:Accepts了,但是花的时间很多,请问如何优化?In Reply To:Accepts了,但是花的时间很多,请问如何优化? Posted by:xiaohao2009 at 2009-04-28 18:09:23 你的一边循环处理一边打印当然慢了。可以牺牲空间来提高实间。就是说定义数组把你处理的结果存放起来,等全部处理完了,再一起打印。这样速度会快一点。我的算法和你的一样,花时204ms。
#include<stdio.h>
char s[1002],s1[1002];
int num[1002];
int main(int argc, char *argv[])
{
int n,i,j,k,m;
char x;
scanf("%d ",&n);
while(n--)
{
scanf("%s",s);
k=0;
for(i=0;s[i];i=m)
{
for(num[k]=1,j=i+1;s[j]==s[i];j++)
num[k]++;
m=j;
s1[k]=s[i];
k++;
}
for(i=0;i<k;i++)
printf("%d%c",num[i],s1[i]);
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator