|
||||||||||
About Pascal
Pascal programs are compiled on the server with Borland Delphi Compiler Version 15.0.
A This is a sample solution for the A + B problem in Pascal:
var i, j : integer; begin while not eof do begin readln(i, j); writeln(i + j); end; end. 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:
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 xorIn 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; begin Sum := a + b; end; function Sum(a, b: integer): integer; begin result := a + b; end; And this code will not be compiled: function Sum(a, b: integer): integer; var result: integer; begin result := a + b; Sum := result; end; A It is useful to know some features of the compiler used on the server.
for i := 1 to 10 do begin if i mod 2 = 0 then inc(i); writeln(i); end;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. var a: array[1..10] of integer; i: integer; begin 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); end. { Delphi output: i = 11 FreePascal output: i = 10 } 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:
var a: int64; b: qword; begin read(a); read(b); writeln(a); writeln(b); end. 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: var a, b: longint; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} readln(a, b); writeln(a + b); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end.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. |
||||||||||
|