Connection Status:
Competition Arena > Ordered
TCCC '03 Round 3 · 2003-03-05 · by brett1479 · Math
Class Name: Ordered
Return Type: String
Method Name: getType
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Given a int[] values containing positive integers return (quotes for clarity):
  • "ASCENDING mean" if the numbers are in increasing order and there are no repeated values,
  • "DESCENDING mean" if the numbers are in decreasing order and there are no repeated values,
  • "NONASCENDING freq" if the numbers are in decreasing order and contain repeated values,
  • "NONDESCENDING freq" if the numbers are in increasing order and contain repeated values,
  • or "NOTHING" if the numbers are none of the above.
where mean is a reduced fraction representing the average of the numbers formatted as (quotes for clarity) "numerator/denominator"
and freq is the number of times the most frequently occurring value occurred in the sequence.
Neither numerator nor denominator should have any leading zeros. For example (quotes for clarity):
values = {1,2,4,11}       return "ASCENDING 9/2" since the average is 18/4 = 9/2
values = {1,2,2,2,3,4}   return "NONDESCENDING 3"  since 2 occurred 3 times
values = {6,5,1}         return "DESCENDING 4/1" since the average is 12/3 = 4/1
values = {5,5,4,4,1}     return "NONASCENDING 2" since 5 occurred twice
values = {1,2,3,4,1}     return "NOTHING" since no other choice is possible

Notes

  • Be sure that you spell everything correctly.

Constraints

  • values must contain between 2 and 50 elements inclusive
  • At least 2 elements of values must be distinct
  • Each element of values must be between 1 and 1000 inclusive
Examples
0)
{1,2,4,11}
Returns: "ASCENDING 9/2"

Increasing order with no repeats

1)
{1,2,2,2,3,4}
Returns: "NONDESCENDING 3"

Increasing order but the 2 is repeated 3 times

2)
{6,5,1}
Returns: "DESCENDING 4/1"

Decreasing order with no repeats

3)
{5,5,4,4,1}
Returns: "NONASCENDING 2"

Decreasing order but there are repeats

4)
{1,2,3,4,1}
Returns: "NOTHING"

The sequence increases at first but decreases at the end

5)
{1000,999,998}
Returns: "DESCENDING 999/1"

Decreasing with no repeats

Submissions are judged against all 27 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Ordered with a public method string getType(vector<int> values) · 27 test cases · 2 s / 256 MB per case

Submitting as anonymous