|  | @@ -0,0 +1,49 @@
 | 
	
		
			
				|  |  | +type pair struct {
 | 
	
		
			
				|  |  | +	_1 int
 | 
	
		
			
				|  |  | +	_2 int
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (p1 *pair) add(p2 pair) {
 | 
	
		
			
				|  |  | +	if p1._1 == 0 {
 | 
	
		
			
				|  |  | +		*p1 = p2
 | 
	
		
			
				|  |  | +	} else {
 | 
	
		
			
				|  |  | +		p1._1 = p1._1*p2._2 + p2._1*p1._2
 | 
	
		
			
				|  |  | +		p1._2 *= p2._2
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func fractionAddition(expression string) string {
 | 
	
		
			
				|  |  | +	beg, end, n := 0, 1, len(expression)
 | 
	
		
			
				|  |  | +	var sum pair
 | 
	
		
			
				|  |  | +	for end < n {
 | 
	
		
			
				|  |  | +		for end = beg + 1; end < n && expression[end] != '+' && expression[end] != '-'; end++ {
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		p := str2frac(expression[beg:end])
 | 
	
		
			
				|  |  | +		sum.add(p)
 | 
	
		
			
				|  |  | +		beg = end
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	i := gcd(abs(sum._1), sum._2)
 | 
	
		
			
				|  |  | +	return fmt.Sprintf("%d/%d", sum._1/i, sum._2/i)
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func gcd(a, b int) int {
 | 
	
		
			
				|  |  | +	if b == 0 {
 | 
	
		
			
				|  |  | +		return a
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return gcd(b, a%b)
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func str2frac(s string) (p pair) {
 | 
	
		
			
				|  |  | +	strs := strings.Split(s, "/")
 | 
	
		
			
				|  |  | +	p._1, _ = strconv.Atoi(strs[0])
 | 
	
		
			
				|  |  | +	p._2, _ = strconv.Atoi(strs[1])
 | 
	
		
			
				|  |  | +	return
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func abs(x int) int {
 | 
	
		
			
				|  |  | +	if x < 0 {
 | 
	
		
			
				|  |  | +		return -x
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return x
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 |