I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes):
char s[1<<27];j;main(i,n){for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;j+=i<n/2?i:n-i,s[i-1]=48+j%10,j/=10);fprintf(fopen("a.out","w"),"%s\n",s);}
This is formated copy:
char s[1<<27];j;
main(i,n){
for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;
j+=i < n/2 ? i: n-i,
s[i - 1] = 48 + j % 10,
j /= 10
);
fprintf(fopen("a.out","w"),"%s\n",s);
}
The best solution of this problem has size 131 bytes, how?