"NEW FUN" (LATVIA)
Programmers often are asked to rewrite old program and the new program
version must keep its functionality. It is nice, if such program is well
documented and source code is available. But not always life is so lucky.
You must rewrite earlier written function FUN about which is known
the following:
1) FUN's arguments are 4 positive integers a_{1},a_{2},a_{3}
and a_{4},
2) FUN's value is one of its arguments values,
3) FUN performs one function of the following kind:
IF a_{i} op a_{j} THEN FUN:=a_{k} ELSE FUN:=a_{m} ;
where possible op values are< , £ , > , ³ , = , ¹, and 1 £i,j,k,m£4.
If i=1, j=2, k=4, m=1, and op is '¹', then we get function
IF a_{1}¹a_{2} THEN FUN:=a_{4} ELSE FUN:=a_{1};(¶)
and we will obtain, for example,FUN(2,1,1,3) = 3, FUN(4,4,2,3) = 4.
It is known, that in practice the existing version is too slow and works properly only if its argument values doesn't exceed 5. You are asked to write a new function version which has to work properly for all positive integer values which do not exceed 32767.
Old FUN version is written so, that this, exactly which function is performed depends on data file in the current catalog FUN.DAT - so it will not be enough if you write a version which performs the same function as old FUN for one fixed FUN.DAT. New version must work properly for any provided FUN.DAT .
Your program will always work in the same environment as old FUN, so you may include in your program old FUN calls (of course, keeping in mind restrictions for argument values). You can asume that in the current catalog always will be valid file FUN.DAT and your new program never will be used without it.
You must write program which performs the same function as old FUN (for any provided FUN.DAT) and for argument values given in input file calculates function values and output them to output file.
The execution time of a call to the old FUN depends neither on the argument values nor on the file FUN.DAT.
Input data
In the first line of text file NEWFUN.IN number of argument sets N (1£N£1000) is given. In the each of the following N lines one argument set (four positive integer values separated by single space characters) is given. All argument values are less or equal to 32767.
Output data
Text file NEWFUN.OUT must contain exactly N rows. In the i-th file row one positive integer - "new FUN" value for i-th argument set must be written.
Technical information for Pascal users
On the diskette in the subdirectory /FUN_PAS the following files are given:
On the diskette in the subdirectory /FUN_C the following files are given: