Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
 Register new ID

About Pascal

<< Back to F.A.Q
Pascal programs are compiled on the server with Borland Delphi Compiler Version 15.0.
Q Are there any examples of solving a problem ?
A This is a sample solution for the A + B problem in Pascal:
var i, j : integer;
   while not eof do
      readln(i, j);
      writeln(i + j);
Q What's new in the 32-bit compiler compared to the 16-bit one ?
A If you are used to writing programs for old 16-bit DOS compilers (for example, for Borland Pascal 7.0), then it would be useful for you to know the following:
  • It is allowed to use arrays of size greater than 64 KB.
  • The type integer is a 32-bit type and coincides with the type longint. The 16-bit signed integer type is called smallint.
  • Strings can be longer than 255 characters. Don't refer to the zero character in order to determine the length of a string; use the function length(s) for this. You can set the length of a string using the procedure setlength(s, n).
Also, there are many new keywords. The following words cannot be redefined or used as identifiers:
and              array                as                asm
begin            case                 class             const
constructor      destructor           dispinterface     div
do               downto               else              end
except           exports              file              finalization
finally          for                  function          goto
if               implementation       in                inherited
initialization   inline               interface         is
label            library              mod               nil
not              object               of                or
out              packed               procedure         program
property         raise                record            repeat
resourcestring   set                  shl               shr
string           then                 threadvar         to
try              type                 unit              until
uses             var                  while             with
In addition, the words protected and published are reserved within the description of an object. Also, the name result in the body of a function is reserved: the value of the corresponding variable is the result of the operation of the function, and a declaration of this name will lead to a compilation error. For example, the following definitions of functions are equivalent:
function Sum(a, b: integer): integer;
   Sum := a + b;

function Sum(a, b: integer): integer;
   result := a + b;

And this code will not be compiled:

function Sum(a, b: integer): integer;
   result: integer;
   result := a + b;
   Sum := result;
Q What are the distinctions of the compiler as compared to other 32-bit Pascal compilers ?
A It is useful to know some features of the compiler used on the server.
  • There are no modules crt and wincrt on the server because they contain procedures that are not needed for solving problems.
  • Dynamic memory allocation involves rounding the size of a block to a multiple of 16 bytes. For example, if you allocate a lot of blocks 4 bytes each, then your program will use four times more memory than you really need. Use static data structures, which are free from this drawback and work faster than dynamic structures.
  • Sets can occupy either 4 or 32 bytes, which also may lead to a significant memory overuse. In many cases a good alternative to sets is using bits of an integer (or of an array of integers).
  • It is forbidden to convert explicitly the types of integer and floating-point variables. For example, the expression "x := extended(i)", where the type of x is extended, and i is integer, is incorrect, whereas the expression "x := i" is valid.
It is forbidden to change the value of the variable of a for loop inside the loop. The following code will not be compiled:
for i := 1 to 10 do
   if i mod 2 = 0 then inc(i);
Moreover, after a for loop the value of the loop variable is not defined. Therefore, this value cannot be used, for example, for a search. The following example will work differently with different compilers.
   a: array[1..10] of integer;
   i: integer;
   for i:=1 to 10 do
      a[i] := i*i;
   for i:=1 to 10 do
      if a[i] = 17 then break;
   writeln('i = ', i);
   Delphi output:      i = 11
   FreePascal output:  i = 10
Q How to use 64-bit integer data types ?
A The compiler fully supports 64-bit integers (both signed and unsigned). A signed 64-bit integer ranges from ¨C9223372036854775808 to 9223372036854775807 and an unsigned 64-bit integer ranges from 0 to 18446744073709551615. The signed type is called int64, and the unsigned type is called qword. The following example illustrates the use of 64-bit integer types:
   a: int64;
   b: qword;
Q Any other notes ?
A Sometimes the Wrong Answer verdict actually means Runtime Error. This is because Delphi independently intercepts some runtime errors and sends a message to the output flow.

In order to increase the size of a stack and to avoid its overflow when using a ˇ°deepˇ± recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB):
{$M 16777216}
It is convenient to use the conditional directive ONLINE_JUDGE for debugging solutions:
   a, b: longint;
   assign(input, 'input.txt');
   assign(output, 'output.txt');
   readln(a, b);
   writeln(a + b);
This program will read data from the file input.txt on your computer and output the result to the file output.txt. On the server, it will use the standard input and output flows.

This page was generated by web cache at 2010-08-08 20:09:59

Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2023 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 0, Server time : 2023-06-01 00:15:59, Gzip enabled