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 1013. K-based Numbers. Version 3

Why my program is Compilation Error?
Posted by hls 6 Aug 2003 09:42
#include <stdio.h>
#include <mem.h>
int num[2000],temp[2000],n,k,c1,c2;
void jian()
{
  int i,tw=0;
  for (i=1998;i>=0;i--)
  {
    if ((num[i]-temp[i]-tw)<0) {num[i]=10+num[i]-temp[i]-tw;tw=1;}
    else {num[i]=num[i]-temp[i]-tw;tw=0;}
    if (i<c2) {c2=i;break;}
  }
}
void cheng(int m)
{
  int i,j,jw,t;
  for (i=1;i<=m;i++)
  {
    jw=0;
    for (j=1998;j>=0;j--)
    {
      t=temp[j];
      temp[j]=(k*temp[j]+jw)%10;
      jw=(k*t+jw)/10;
      if ((j<=c1)&&(jw==0)) {c1=j;break;}
    }
  }
  i=1998;
  while (i>=0)
  {
    if (temp[i]>0) {temp[i]--;break;}
    else {temp[i]=9;i--;}
  }
}
int main()
{
  int i,j;
  scanf("%d %d",&n,&k);
  c2=0;
  for (i=n;i>=1;i--)
  {
    for (j=0;j<=1998;j++) temp[j]=0;
    temp[1998]=1;
    c1=1998;
    cheng(i);
    if (i==n) for (j=0;j<=1998;j++) num[j]=temp[j];
    else jian();
  }
  for (i=0;i<=1998;i++)
    if (num[i]!=0) {j=i;break;}
  for (i=j;i<=1998;i++)
    printf("%d",num[i]);
  printf("\n");
  return 0;
}
if you get compile error,it will send you an e_mail... ...(see it)
Posted by Seany 6 Aug 2003 13:08
> #include <stdio.h>
> #include <mem.h>
> int num[2000],temp[2000],n,k,c1,c2;
> void jian()
> {
>   int i,tw=0;
>   for (i=1998;i>=0;i--)
>   {
>     if ((num[i]-temp[i]-tw)<0) {num[i]=10+num[i]-temp[i]-tw;tw=1;}
>     else {num[i]=num[i]-temp[i]-tw;tw=0;}
>     if (i<c2) {c2=i;break;}
>   }
> }
> void cheng(int m)
> {
>   int i,j,jw,t;
>   for (i=1;i<=m;i++)
>   {
>     jw=0;
>     for (j=1998;j>=0;j--)
>     {
>       t=temp[j];
>       temp[j]=(k*temp[j]+jw)%10;
>       jw=(k*t+jw)/10;
>       if ((j<=c1)&&(jw==0)) {c1=j;break;}
>     }
>   }
>   i=1998;
>   while (i>=0)
>   {
>     if (temp[i]>0) {temp[i]--;break;}
>     else {temp[i]=9;i--;}
>   }
> }
> int main()
> {
>   int i,j;
>   scanf("%d %d",&n,&k);
>   c2=0;
>   for (i=n;i>=1;i--)
>   {
>     for (j=0;j<=1998;j++) temp[j]=0;
>     temp[1998]=1;
>     c1=1998;
>     cheng(i);
>     if (i==n) for (j=0;j<=1998;j++) num[j]=temp[j];
>     else jian();
>   }
>   for (i=0;i<=1998;i++)
>     if (num[i]!=0) {j=i;break;}
>   for (i=j;i<=1998;i++)
>     printf("%d",num[i]);
>   printf("\n");
>   return 0;
> }
Just delete string "#include <mem.h>" (-)
Posted by Renat Mullakhanov 7 Aug 2003 11:22
> #include <stdio.h>
> #include <mem.h>
> int num[2000],temp[2000],n,k,c1,c2;
> void jian()
> {
>   int i,tw=0;
>   for (i=1998;i>=0;i--)
>   {
>     if ((num[i]-temp[i]-tw)<0) {num[i]=10+num[i]-temp[i]-tw;tw=1;}
>     else {num[i]=num[i]-temp[i]-tw;tw=0;}
>     if (i<c2) {c2=i;break;}
>   }
> }
> void cheng(int m)
> {
>   int i,j,jw,t;
>   for (i=1;i<=m;i++)
>   {
>     jw=0;
>     for (j=1998;j>=0;j--)
>     {
>       t=temp[j];
>       temp[j]=(k*temp[j]+jw)%10;
>       jw=(k*t+jw)/10;
>       if ((j<=c1)&&(jw==0)) {c1=j;break;}
>     }
>   }
>   i=1998;
>   while (i>=0)
>   {
>     if (temp[i]>0) {temp[i]--;break;}
>     else {temp[i]=9;i--;}
>   }
> }
> int main()
> {
>   int i,j;
>   scanf("%d %d",&n,&k);
>   c2=0;
>   for (i=n;i>=1;i--)
>   {
>     for (j=0;j<=1998;j++) temp[j]=0;
>     temp[1998]=1;
>     c1=1998;
>     cheng(i);
>     if (i==n) for (j=0;j<=1998;j++) num[j]=temp[j];
>     else jian();
>   }
>   for (i=0;i<=1998;i++)
>     if (num[i]!=0) {j=i;break;}
>   for (i=j;i<=1998;i++)
>     printf("%d",num[i]);
>   printf("\n");
>   return 0;
> }