ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1189. Pairs of Integers

Why 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;

    // &#1112;&#1084;&#1030;&#1081;Y&#1050;&#1047;&#1059;&#1049;X&#1029;&#1064;&#1048;&#1168;&#1044;&#169;&#1054;&#187;&#181;&#1043;&#181;&#1029;&#181;&#1044;&#1047;&#1081;&#1111;&#1094;
    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;
            // &#181;&#1066;&#1058;&#187;&#1062;&#1062;&#1047;&#1081;&#1111;&#1094;
            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);
            }
            // &#181;&#1066;&#182;&#1102;&#1062;&#1062;&#1047;&#1081;&#1111;&#1094;
            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);
    }
}