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 1009. K-based Numbers

Why did my program compile error?
Posted by lyj_george 5 Feb 2002 13:39
In this program n is k , k is n
var
  l : array [1..1000] of byte;
  n , k , ss : integer;
  tot : longint;
function cf(aa,bb:integer) : longint;
var
  temp , ii : longint;
begin
  temp := 1;
  for ii := 1 to bb do
    temp := temp * aa;
  cf := temp;
end;
procedure try(now,left,source : integer);
var
  jj : byte;
begin
  if left = 0 then begin
    tot := tot + cf(n-1,k-source);
    exit;
  end;
  if now > k then exit;
  if left > k - now+1 then exit;
  for jj := 0 to 1 do
    if (jj = 0) or ((jj=1) and (l[now-1]<>1)) then begin
      l[now] := jj;
      try(now+1 , left-jj , source);
    end;
end;

begin
  readln(k);
  readln(n);
  tot := cf(n-1,k);
  for ss := 1 to k-1 do
   try(2,ss,ss);
  writeln(tot);
end.
Re: Why did my program compile error?
Posted by Stupnikov Pavel 5 Feb 2002 18:21
> In this program n is k , k is n
> var
>   l : array [1..1000] of byte;
>   n , k , ss : integer;
>   tot : longint;
> function cf(aa,bb:integer) : longint;
> var
>   temp , ii : longint;
> begin
>   temp := 1;
>   for ii := 1 to bb do
>     temp := temp * aa;
>   cf := temp;
> end;
> procedure try(now,left,source : integer);
> var
>   jj : byte;
> begin
>   if left = 0 then begin
>     tot := tot + cf(n-1,k-source);
>     exit;
>   end;
>   if now > k then exit;
>   if left > k - now+1 then exit;
>   for jj := 0 to 1 do
>     if (jj = 0) or ((jj=1) and (l[now-1]<>1)) then begin
>       l[now] := jj;
>       try(now+1 , left-jj , source);
>     end;
> end;
>
> begin
>   readln(k);
>   readln(n);
>   tot := cf(n-1,k);
>   for ss := 1 to k-1 do
>    try(2,ss,ss);
>   writeln(tot);
> end.
>
1. warning: missing program header;
With header my GPC compiled your program? but ...
2. While trying to solve this problem and checking my e-mail i find
one error: function or procedure can't use name 'try'. When i change
'try' in your program to 'trye', your program solve the problem. Thank
you for your code :-)
Header?What is it?Turbo Pascal doesn't need header?
Posted by lyj_george 6 Feb 2002 08:59
I've known that procedure or function name can't use "try".Thank you
for your help.