Site Navigation
|
International Schools Software Competition 99 Tasks
|
String |
Longest sub-string |
Length |
ABCDEABC |
ABC |
3 |
XYXYX |
XYX |
3 |
AXAYAZA |
A |
1 |
GHI |
|
0 |
The sample input and output files for the first example are shown below.
Sample input:
ABCDEABC
Sample output:
3
In a small town with n (where 4 ≤ n ≤ 20) bus-stops, the bus stops are
labeled 1, 2, 3, ., n. The routes of the bus service are given as a list of
directed segments. For example, the following diagram shows a town with 5
bus-stops, and 6 segments:
Every segment links two different bus-stops, and no segment is duplicated.
You are to determine the length of the shortest loop in the route. There
are two loops in the example, one loops through bus-stops 1, 2, 4 and hence has
a length of 3; and another loops through bus-stops 1, 2, 4, 3, and has a length
of 4. The length of the shortest loop is hence 3.
If there is no loop in the routes, you are to input:
There is no loop.
Note that the smallest loop possible has length 2, one that starts from bus-stop
x, goes to bus-stop y, and back to x.
The input file contains 2 ingredients, n and k, on the first line: n is the
number of bus-stops, and the k is number of segments. The segments are given in
the subsequent k lines, with each segment represented by the bus-stop where it
ends. You are to write the answer into a output file. The sample input and
output files for the above example are shown below.
Sample input:
5 6
1 2
2 5
4 1
3 1
2 4
4 3
Sample output:
3
A unique-index element of a multidimensional array is an element with no
duplicate subscripts. For example, A[2] [1], B[13] [4] [6], and C[111] [22] [3]
[4444] [55] are unique-index elements, whereas A[2] [2], B[13] [4] [4] and C
[111] [22] [3] [4444] [3] are not.
Your task is to determine the number of unique-index elements there are
within a specified portion of a multidimensional array.
For example, for the portion of a two-dimensional array A [i] [j] where 3<= i<=6 and 4<=j<=5, the unique-index elements are:
A [3] [4], A[3] [5], A [4] [5], A [5] [4], A [6] [4], A [6] [5].
Since there are 6 such elements, the answer is 6.
The first line of the input file is a positive integer representing the number
of dimensions in the array. Each remaining line of the input file will have two
positive integers (with the second integer greater than or equal to the first)
which specify the range of the respective subscript.
You may assume that:
- Every number in the input file is a ppositive integer less than 100
- The total number of array elements inn the specified portion of the
multidimensional array is less than 10,000.
You are to write the answer into an output file. The sample input and output
files for the above example are shown below.
Sample input:
2
3 6
4 5
Sample output:
6