|
|
back to boardWhy I got WA? Posted by Yasker 5 Mar 2002 17:44 #include <stdio.h> #include <string.h> FILE *fin, *fout; long n; long num, ans[20]; void add(long x); void out(); main() { long x1, x2, y, z; long t, n2, res; fin=stdin; fout=stdout; fscanf(fin, "%d", &n); num=0; // јмІйYКЗУЙXЅШИҐД©О»µГµЅµДЗйїц y=n % 11; if ( y<10 ) { x1=(n-y)/11; res=x1*10+y; if ( res+res>n ) add(res); } if ( n % 2==0 ) { t=10; while ( t<=n ) { z=n % t; n2=n/t; // µЪТ»ЦЦЗйїц x1=z/2; y=n2 % 11; if ( y<10 ) { x2=(n2-y)/11; res=(x2*10+y)*t+x1; if ( res+res>n ) add(res); } // µЪ¶юЦЦЗйїц x1=(z+t)/2; --n2; y=n2 % 11; if ( y<10 ) { x2=(n2-y)/11; res=(x2*10+y)*t+x1; if ( res+res>n ) add(res); } t=t*10; } } out(); fclose(fin); fclose(fout); } void add(long x) { int i;
i=1; while ( i<=num && x>ans[i] ) ++i; if ( x!=ans[i] ) { ++num; if ( i<num ) memmove(ans+i+1, ans+i, (num-i)*sizeof(int)); ans[i]=x; } } void out() { int i; long x, y;
fprintf(fout, "%d\n", num); for ( i=1; i<=num; ++i ) { fprintf(fout, "%d + ", ans[i]); x=n-ans[i]; y=1; while ( y*100<ans[i] ) y=y*10; while ( y>x && y>1 ) { fprintf(fout, "%d", 0); y=y/10; } fprintf(fout, "%d = %d\n", x, n); } } |
|
|