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 1165. Subnumber

need help
Posted by daizi sheng(from USTC) 16 Oct 2002 15:09
00000->99999 have been accepted by my source
(using KMP to judge it)

but it is still got WR


#include<stdio.h>
#include<string.h>

#define MAX 350
/*&#1105;&#1071;&#1109;&#171;&#182;&#1048;&#1169;&#1098;&#1042;&#1083;*/

void add(int a[],int la,int b[],int lb,int c[],int *lc){
    int i;
    int flag = 0;

    /*init*/
    for(i = 0;i < MAX;i++)
        c[i] = 0;

    for(i = 0;i <(la>lb?la:lb);i++){
        c[i] = (flag + a[i] + b[i])%10;
        flag = (flag + a[i] + b[i])/10;
        }

    if(flag != 0)
        c[i++] = flag;

    (*lc) = i;
    }

void sub(int a[],int la,int b[],int lb,int c[],int *lc){
    /*make sure that a >= b
        make sure that la >= lb*/
    int i;
    int flag = 0;
    int t;

    for(i = 0;i < MAX;i++)
        c[i] = 0;

    for(i = 0;i <la;i++){
        t = a[i] - b[i] -flag;
        if(t < 0){
            t += 10;
            flag = 1;
            c[i] = t;
            }
        else{
            flag = 0;
            c[i] = t;
            }
        }

    (*lc) = 0;
    for(i = MAX-1;i >= 0;i--){
        if(c[i] != 0){
            (*lc) = i + 1;
            break;
            }
        }
    if((*lc) == 0) (*lc) = 1;
    lb -= lb;
    }
int sub1(int digit[],int *l)
{
    int flag = -1;
    int i;
    int t;
    for(i = 0;i < (*l);i++)
    {
        t = digit[i] + flag;
        if(t < 0)
        {
            flag = -1;
            t += 10;
        }
        else
        {
            digit[i] = t;
            break;
        }
        digit[i] = t;
    }
    if(digit[*l - 1] == 0)
    {
        (*l)--;
    }
    return 0;
}

int add1(int digit[],int *l)
{
    int flag = 1;
    int i;
    int t;
    for(i = 0;i <= (*l);i++)
    {
        t = digit[i] + flag;
        if(t >= 10)
        {
            flag = 1;
            t -= 10;
        }
        else
        {
            digit[i] = t;
            break;
        }
        digit[i] = t;
    }
    if(digit[*l] != 0)
    {
        (*l)++;
    }
    return 0;
}

void mul(int a[],int la,int b[],int lb,int c[],int *lc){
    int i,j;
    int flag,t;

    /*init*/
    for(i = 0;i < MAX;i++)
        c[i] = 0;

    if(la == 1 &&a[0] == 0 ||
        lb == 1&&b[0] == 0){
            (*lc) = 1;
            return;
            }
    for(i = 0;i <la;i++){
        flag = 0;
        for(j = 0;j < lb;j++){
            t = c[i + j] + a[i] * b[j] + flag;
            c[i + j] = t%10;
            flag = t/10;
            }
        while(flag > 0){
            t = c[i + j] + flag;
            c[i + j] = t%10;
            flag = t/10;
            j++;
            }
        }
    if(c[la+lb-1] != 0)
        (*lc) = la+lb;
    else
        (*lc) = la + lb -1;
    }

void let(int a[],int *la,int b[],int lb){
    int i;
    for(i = 0;i< MAX;i++)
        a[i] = b[i];
    (*la) = lb;
    }
void make(int a,int r[],int *lb){
    int i;

    /*init*/
    for(i = 0;i < MAX;i++)
        r[i] = 0;

    i = 0;
    while(a > 0){
        r[i] = a%10;
        a /= 10;
        i++;
        }
    if(i == 0)
        (*lb) = 1;
    else
        (*lb) = i;
    }

void output(int a[],int la){
    int i;
    for(i = la -1;i >= 0;i--)
        printf("%d",a[i]);
    }

int compare(int a[],int la,int b[],int lb)
{
    int i;
    if(la > lb)
    {
        return 1;
    }
    if(lb > la)
    {
        return -1;
    }
    for(i = la - 1;i >= 0;i--)
    {
        if(a[i] > b[i])
        {
            return 1;
        }
        if(a[i] < b[i])
        {
            return -1;
        }
    }
    return 0;
}

/*&#1105;&#1071;&#1109;&#171;&#182;&#1048;&#1169;&#1098;&#1042;&#1083;&#1029;&#1073;&#1050;&#1096;*/

#define MAXLEN 205
int checklist[MAXLEN][MAX];
int checklen[MAXLEN];
/*checklist[i] = the index of 10...0(i zeros)*/

int check_init(void)
{
    int i;
    int t[MAX],lt;
    int a[MAX],la;
    int b[MAX],lb;
    int c[MAX],lc;
    int nine[MAX],lnine;

    make(9,nine,&lnine);

    make(1,checklist[0],checklen + 0);
    for(i = 1;i < MAXLEN;i++)
    {
        make(0,t,&lt);
        t[i - 1] = 1;
        lt = i;/*10 ^ (i - 1) */
        mul(nine,lnine,t,lt,a,&la);/*9 * 10 ^ ( i - 1) */
        make(i,b,&lb);/* i */
        mul(b,lb,a,la,c,&lc);/*i * 9 * 10 ^ ( i - 1) */
        add(c,lc,checklist[i - 1],checklen[i - 1],
                checklist[i],checklen + i);