TopCoder problem "Arithmetic" used in SRM 33 (Division I Level One , Division II Level One)



Problem Statement

    
Class name: Arithmetic
Method name: getResult
Parameters: int, char, int
Returns: int[]

Implement a class Arithmetic, which has a method getResult.

The method signature is (be sure your method is public): 
int[] getResult(int a, char op, int b)

*a is between 0 and 255, inclusive
*op is either '+' or '*'
*b is between 0 and 255, inclusive

if op is '+', then 
	result = a + b
if op is '*', then
	result is a * b

The return value should be an array of type int with 2 elements.
The first element will be the remainder of result when divided by 256.
The second element will be the quotient of result when divided by 256.

The remainder and quotient would be calculated as follows:
if we are dividing x by y, then the quotient is the largest positive integer q
such that
q * y (multiplication) is less than or equal to x, and x - (q * y) is less than
y.
The remainder is the difference x - (q * y).
If x = 13, and y = 3, then
quotient = 4, and remainder = 1 because
3 * 4 = 12 <= 13 and 13 - 12 = 1 < 3.
If x = 10, and y = 5, then
quotient = 2, and remainder = 0 because
2 * 5 = 10 <= 10, and 10 - 10 = 0 < 2.


Examples:

---------------
op = '+'
---------------

a = 200
b = 3
op = '+'
return { 203, 0 }

a = 200
b = 0
op = '+'
return { 200, 0 }

a = 200
b = 56
op = '+'
return { 0, 1 }

a = 255
b = 0
op = '+'
return { 255, 0 }

a = 255
b = 255
op = '+'
return { 254, 1 }


---------------
op = '*'
---------------

a = 200
b = 3
op = '*'
return { 88, 2 }

a = 200
b = 0
op = '*'
return { 0, 0 }

a = 200
b = 56
op = '*'
return { 192, 43 }

a = 255
b = 1
op = '*'
return { 255, 0 }

a = 255
b = 255
op = '*'
return { 1, 254 }
 

Definition

    
Class:Arithmetic
Method:getResult
Parameters:int, char, int
Returns:int[]
Method signature:int[] getResult(int param0, char param1, int param2)
(be sure your method is public)
    

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=174

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4003&pm=174

Writer:

jay_peg

Testers:

Problem categories: