一道ACM题,提交后说结果错,但实在是看不出错在哪里了,该如何处理

一道ACM题,提交后说结果错,但实在是看不出错在哪里了
题目在http://acm.zju.edu.cn/show_problem.php?pid=1115
我写的程序,看不出哪里不和他的要求了...


#include   <iostream.h>


int   main()
{
        int   a[1000],j[1000],k=0,m=0,p=0,s,i,l;
        for(i=0;i <=1000;i++)
{cin> > a[i];
if(a[i]==0){break;}
    else
    {  
p=a[i];
m=p%10;
k=p/10;
s=m+k;
j[i]=s;
        while(s> =10)
{

{m=s%10;
  k=s/10;
  s=m+k;}
j[i]=s;

}
 
  }
        l=i;
       

}
for(i=0;i <=l;i++)
{cout < <j[i] < <endl;}

        return   0;
}

------解决方案--------------------
下面是我做的,供参考
// Accepted 1115 C++ 00:00.00 396K
#include <stdio.h>
#include <string.h>

int main(void)
{
char str[1002];
int i, res, len, n;
while(scanf( "%s ", str)!=EOF) {
len = strlen(str);
if(len==1 && str[0]== '0 ') break;
n = 0;
for(i=0; i <len; i++)
n += str[i] - '0 ';
while( true ) {
res = 0;
while( n ) {
res += n%10;
n /= 10;
}
n = res;
if(n < 10) {
printf( "%d\n ", n);
break;
}
}
}
return 0;
}