Tap here to switch tabs
Problem
Submissions

Problem: Fraction Addition and Subtraction

med
30 min
Try to solve the Fraction Addition and Subtraction problem.

Statement

Given a string expression representing an expression of fraction addition and subtraction, return the calculation result as a string in the format of an irreducible fraction.

The format for each fraction is ±numerator/denominator. If the first fraction in the input or the final result is positive, the leading '+' is omitted.

Note: An irreducible fraction is a fraction where the numerator and denominator have a greatest common divisor equal to 11. If the final result is an integer, the denominator must still be represented as 11.

Constraints:

  • The input string expression only contains '0' to '9', '/', '+', and '-'.

  • Each fraction follows the format ±numerator/denominator.

  • The input contains only valid irreducible fractions, where the numerator and denominator of each fraction are in the range [1,10][1, 10].

  • The number of fractions in expression is in the range [1,10][1, 10].

  • The numerator and denominator of the final result are guaranteed to fit in a 3232 bit signed integer.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Fraction Addition and Subtraction

med
30 min
Try to solve the Fraction Addition and Subtraction problem.

Statement

Given a string expression representing an expression of fraction addition and subtraction, return the calculation result as a string in the format of an irreducible fraction.

The format for each fraction is ±numerator/denominator. If the first fraction in the input or the final result is positive, the leading '+' is omitted.

Note: An irreducible fraction is a fraction where the numerator and denominator have a greatest common divisor equal to 11. If the final result is an integer, the denominator must still be represented as 11.

Constraints:

  • The input string expression only contains '0' to '9', '/', '+', and '-'.

  • Each fraction follows the format ±numerator/denominator.

  • The input contains only valid irreducible fractions, where the numerator and denominator of each fraction are in the range [1,10][1, 10].

  • The number of fractions in expression is in the range [1,10][1, 10].

  • The numerator and denominator of the final result are guaranteed to fit in a 3232 bit signed integer.