Problem:


Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7



Sample input:
1222


Sample output:
1+2+2+2=7

Submission status: Accepted

Solution code:
num_text = list(input())
a = int(num_text[3])
b = int(num_text[2])
c = int(num_text[1])
d = int(num_text[0])
sum = 0
flg = 0
sum = d + c + b + a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'+'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d + c + b - a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'+'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d + c - b + a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'-'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d + c - b - a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'-'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d - c + b + a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'+'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d - c + b - a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'+'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d - c - b + a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'-'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d - c - b - a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'-'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1

Submission status: Accepted

Solution code:
import math
import sys

N = input()

a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])


OP1 = ["+","-"]
OP2 = ["+","-"]
OP3 = ["+","-"]


for op1 in OP1:


    if op1 == "+":
        ab = a + b
    else:
        ab = a - b

    for op2 in OP2:
        if op2 == "+":
            abc = ab + c
        else:
            abc = ab - c

        for op3 in OP3:
            if op3 == "+":
                abcd = abc + d
            else:
                abcd = abc - d

            if abcd == 7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                sys.exit(0)

Submission status: Accepted

Solution code:
A, B, C, D = (int(i) for i in str(input()))

if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
elif A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
elif A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
elif A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
elif A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
elif A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
elif A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
elif A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a,b,c,d = map(int, list(input()))

for op1 in ["+","-"]:
    for op2 in ["+","-"]:
        for op3 in ["+","-"]:
            res = 0
            if op1=="+":
                res += a+b
            else:
                res += a-b
            if op2=="+":
                res += c
            else:
                res -= c
            if op3=="+":
                res += d
            else:
                res -= d
            if res==7:
                print("".join([str(a),op1,str(b),op2,str(c),op3,str(d),"=7"]))
                exit()

Submission status: Accepted

Solution code:
def getanswer(num, ops, total):
    idx = len(ops)
    if idx == 3:
        return ops if total == 7 else None
    return getanswer(num, ops + "+", total + num[idx+1]) or \
        getanswer(num, ops + "-", total - num[idx+1])


def main():
    num = [int(x) for x in input()]
    ops = getanswer(num, "", num[0])
    retval = ""
    for i in range(3):
        retval += str(num[i]) + ops[i]
    retval += str(num[3]) + "=7"
    print(retval)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# きたない。。。。
def get_formula(a,b,c,d) :
	for f1 in range(2) :
		s = str(a)
		if (f1 == 0) :
			s += "+"
		else : 
			s += "-"
		
		s += str(b)
		for f2 in range(2) :
			s2 = s
			if (f2 == 0) :
				s2 += "+"
			else : 
				s2 += "-"
			
			s2 += str(c)
			for f3 in range(2) :
				s3 = s2
				if (f3 == 0) :
					s3 += "+"
				else : 
					s3 += "-"
				
				s3 += str(d)
				if (eval(s3) == 7) :
					return s3

a,b,c,d = [int(i) for i in list(input())]

print(get_formula(a,b,c,d) + "=7")

Submission status: Accepted

Solution code:
S = list(str(input()))
A = S[0]
B = S[1]
C = S[2]
D = S[3]
a = int(A)
b = int(B)
c = int(C)
d = int(D)
if a+b+c+d == 7:
    print(A+"+"+B+"+"+C+"+"+D+"=7")
elif a-b+c+d == 7:
    print(A+"-"+B+"+"+C+"+"+D+"=7")
elif a+b-c+d == 7:
    print(A+"+"+B+"-"+C+"+"+D+"=7")
elif a+b+c-d == 7:
    print(A+"+"+B+"+"+C+"-"+D+"=7")
elif a-b-c+d == 7:
    print(A+"-"+B+"-"+C+"+"+D+"=7")
elif a-b+c-d == 7:
    print(A+"-"+B+"+"+C+"-"+D+"=7")
elif a+b-c-d == 7:
    print(A+"+"+B+"-"+C+"-"+D+"=7")
elif a-b-c-d == 7:
    print(A+"-"+B+"-"+C+"-"+D+"=7")

Submission status: Accepted

Solution code:
import itertools
A, B, C, D = [int(_) for _ in input()]
B = [-B, B]
C = [-C, C]
D = [-D, D]
for i, j, k in itertools.product(range(2), repeat=3):
    if A + B[i] + C[j] + D[k] == 7:
        print('+'.join(map(str, [A, B[i], C[j], D[k]])).replace('+-', '-') + '=7')
        exit()

Submission status: Accepted

Solution code:
n = list(input())
def saiki(list_1,list_2,t): # 1 <= int t <= 3 
    for e in list_1:
        for b in [0,1]:
            if b == 0:
                list_2.append(e + "+" + n[t])
            elif b == 1:
                list_2.append(e + "-" + n[t])
    list_1.clear()
    if t < 3:
        return saiki(list_2,list_1,t+1)
    else:
        return list_2
list_1 = [n[0]]
list_2 = []
t = 1
list_3 = saiki(list_1,list_2,t)
for i in list_3:
    result = int(i[0])
    for j in [1,3,5]:
        if i[j] == "+":
            result += int(i[j+1])
        elif i[j] == "-":
            result -= int(i[j+1])
    if result == 7:
        print(i + "=7")
        exit()

Submission status: Accepted

Solution code:
from sys import exit
def fun(arr,i,j,k):
    ans = arr[0]
    if i == '+':
        ans += arr[1]
    else:
        ans += -arr[1]
    if j == '+':
        ans += arr[2]
    else:
        ans -= arr[2]
    if k == '+':
        ans += arr[3]
    else:
        ans -= arr[3]
    return ans
s = raw_input().strip()
s = [int(x) for x in s]
for i in ['+','-']:
    for j in ['+','-']:
        for k in ['+','-']:
            if fun(s,i,j,k) == 7:
                print str(s[0])+i+str(s[1])+j+str(s[2])+k+str(s[3])+"=7"
                exit(0)

Submission status: Accepted

Solution code:
a = list(input())
ar = [["+","-"],["+","-"],["+","-"]]
count = 0
t = 0
for x in ar[0]:
    for y in ar[1]:
        for z in ar[2]:
            count += int(a[0])
            if x == "+":
                count += int(a[1])
            elif x == "-":
                count -= int(a[1])
            if y == "+":
                count += int(a[2])
            elif y == "-":
                count -= int(a[2])
            if z == "+":
                count += int(a[3])
            elif z == "-":
                count -= int(a[3])
            if count == 7 and t ==0:
                print(a[0]+x+a[1]+y+a[2]+z+a[3]+"=7")
                t += 1
            count = 0

Submission status: Accepted

Solution code:
s = input()
op = ["+", "-"]


def caliculation(sum, operator, _input):
    if op[operator] == "+":
        sum += _input
    elif op[operator] == "-":
        sum -= _input
    return sum


for i in range(2):
    for j in range(2):
        for k in range(2):
            sum = int(s[0])
            sum = caliculation(sum, i, int(s[1]))
            sum = caliculation(sum, j, int(s[2]))
            sum = caliculation(sum, k, int(s[3]))
            if sum == 7:
                print("{}{}{}{}{}{}{}{}".format(s[0], op[i], s[1], op[j], s[2], op[k], s[3], "=7"))
                exit()

Submission status: Accepted

Solution code:
S = input()
op = ["+", "-"]
for a in op:
    for b in op:
        for c in op:
            f = S[0] + a + S[1] + b + S[2] + c + S[3]
            if eval(f) == 7:
                print(f + "=7")
                break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Accepted

Solution code:
S = input()
op = ["+", "-"]
for a in op:
    for b in op:
        for c in op:
            f = S[0] + a + S[1] + b + S[2] + c + S[3]
            if eval(f) == 7:
                print(f + "=7")
                exit()

Submission status: Accepted

Solution code:
S=input()
op=["+","-"]
for a in op:
    for b in op:
        for c in op:
            f=S[0]+a+S[1]+b+S[2]+c+S[3]
            if eval(f)==7:
                print(f+"=7")
                exit()

Submission status: Accepted

Solution code:
abcd = input()

for i in range(1<<3):
	formula = abcd[0]
	for j in range(3):
		formula += "+-"[(i>>j)%2]
		formula += abcd[j+1]
	if eval(formula) == 7:
		print(formula + "=7")
		exit()

Submission status: Accepted

Solution code:
s=input()
a=int(s[0]);b=int(s[1]);c=int(s[2]);d=int(s[3])
if a+b+c+d==7:print(s[0]+'+'+s[1]+'+'+s[2]+'+'+s[3]+'='+'7')
elif a-b+c+d==7:print(s[0]+'-'+s[1]+'+'+s[2]+'+'+s[3]+'='+'7')
elif a+b-c+d==7:print(s[0]+'+'+s[1]+'-'+s[2]+'+'+s[3]+'='+'7')
elif a+b+c-d==7:print(s[0]+'+'+s[1]+'+'+s[2]+'-'+s[3]+'='+'7')
elif a-b-c+d==7:print(s[0]+'-'+s[1]+'-'+s[2]+'+'+s[3]+'='+'7')
elif a-b+c-d==7:print(s[0]+'-'+s[1]+'+'+s[2]+'-'+s[3]+'='+'7')
elif a+b-c-d==7:print(s[0]+'+'+s[1]+'-'+s[2]+'-'+s[3]+'='+'7')
elif a-b-c-d==7:print(s[0]+'-'+s[1]+'-'+s[2]+'-'+s[3]+'='+'7')

Submission status: Accepted

Solution code:
NN = list(input())
 
for i in range(2**3):
    N = NN[:]
    for j in range(3):
        if i & 2**j:
            if j == 0:
                N.insert(1, '+')
            elif j == 1:
                N.insert(3, '+')
            else:
                N.insert(5, '+')
        else:
            if j == 0:
                N.insert(1, '-')
            elif j == 1:
                N.insert(3, '-')
            else:
                N.insert(5, '-')
    if eval(''.join(N)) == 7:
        print(''.join(N)+'=7')
        break

Submission status: Accepted

Solution code:
NN = list(input())

for i in range(2**3):
    N = NN[:]
    for j in range(3):
        if i & (1 << j):
            if j == 0:
                N.insert(1, '+')
            elif j == 1:
                N.insert(3, '+')
            else:
                N.insert(5, '+')
        else:
            if j == 0:
                N.insert(1, '-')
            elif j == 1:
                N.insert(3, '-')
            else:
                N.insert(5, '-')
    if eval(''.join(N)) == 7:
        print(''.join(N)+'=7')
        break

Submission status: Accepted

Solution code:
ABCD = input()
ABCD = list(int(ABCD[i]) for i in range(4))

for i in range(8):
    result = ABCD[0]
    for j in range(3):
        if (1<<j & i)>>j:
            result += ABCD[j+1]
        else:
            result -= ABCD[j+1]

    if result == 7:
        result = i
        break

print(ABCD[0], end='')
print('+' if 1 & result else '-', end='')
print(ABCD[1], end='')
print('+' if 10 & result else '-', end='')
print(ABCD[2], end='')
print('+' if 100 & result else '-', end='')
print(str(ABCD[3]) + '=7')

Submission status: Accepted

Solution code:
n = input()
s = [int(i) for i in n]
v = 0
w = ''
for p in range(2):
  if p == 0:
    v = s[0] + s[1]
    w = n[0] + "+" + n[1]
  else:
    v = s[0] - s[1]
    w = n[0] + "-" + n[1]
  for q in range(2):
    if q == 0 and p == 0:
      v += +s[2]
      w += "+" + n[2]
    elif q == 1 and p == 0:
      v = s[0] + s[1] - s[2]
      w =  n[0] + "+" + n[1] + "-" + n[2]
    elif q == 0 and p == 1:
      v += +s[2]
      w += "+" + n[2]
    elif q == 1 and p == 1: 
      v = s[0] - s[1] - s[2]
      w =  n[0] + "-" + n[1] + "-" + n[2]
    for r in range(2):
      if r == 0:
        if v+s[3] == 7:
          print(w + "+" + n[3] + "=7")
          exit()
      else:
        if v-s[3] == 7:
          print(w + "-" + n[3] + "=7")
          exit()

Submission status: Accepted

Solution code:
if __name__=='__main__':
  sums=0
  num=[x for x in range(1,4)]
  S=list(map(int,input()))
  answer=[S[0],'a',S[1],'b',S[2],'c',S[3]]
  for i in range(1<<3):
    output=[]
    for j in range(3):
      if ((i>>j)&1)==1:
        output.append(num[j])
    plus=[S[o] for o in output]
    sabun=list(filter(lambda x: x not in output, num))
    mins=[S[m] for m in sabun]
    if sum(plus)-sum(mins)+S[0]==7:
      for o in output:
        answer[2*o-1]='+'
      for m in sabun:
        answer[2*m-1]='-'
      answer=map(str, answer)
      print(''.join(answer)+'=7')
      break

Submission status: Accepted

Solution code:
a, b, c, d = map(int,input())

if a-b-c-d == 7: print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7: print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7: print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b+c+d == 7: print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7: print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7: print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7: print('{}+{}+{}-{}=7'.format(a,b,c,d))
else: print('{}+{}+{}+{}=7'.format(a,b,c,d))

Submission status: Accepted

Solution code:
num_str = list(str(input()))
num = []
for i in range(4):
    num.append(int(num_str[i]))
if num[0] + num[1] + num[2] + num[3] == 7:
    print(num[0], "+", num[1], "+", num[2], "+", num[3], "=7", sep="")
    
elif num[0] - num[1] + num[2] + num[3] == 7:
    print(num[0], "-" ,num[1] ,"+", num[2] ,"+" ,num[3] ,"=7", sep="")
    
elif num[0] + num[1] - num[2] + num[3] == 7:
    print(num[0], "+" ,num[1] ,"-" ,num[2], "+", num[3] ,"=7", sep="")
    
elif num[0] + num[1] + num[2] - num[3] == 7:
    print(num[0], "+", num[1], "+" ,num[2], "-", num[3], "=7", sep="")
    
elif num[0] - num[1] - num[2] + num[3] == 7:
    print(num[0] ,"-" ,num[1], "-" ,num[2] ,"+" ,num[3] ,"=7", sep="")
    
elif num[0] - num[1] + num[2] - num[3] == 7:
    print(num[0] ,"-" ,num[1] ,"+" ,num[2] ,"-", num[3], "=7", sep="")
    
elif num[0] - num[1] - num[2] - num[3] == 7:
    print(num[0] ,"-", num[1], "-" ,num[2] ,"-", num[3],"=7", sep="")
    
elif num[0] + num[1] - num[2] - num[3] == 7:
    print(num[0], "+" ,num[1] ,"-" ,num[2], "-" ,num[3], "=7", sep="")

Submission status: Accepted

Solution code:
import queue

def check(operator_list, num_list):
    res = num_list[0]
    for i, op in enumerate(operator_list):
        if op == '+':
            res += num_list[i + 1]
        elif op == '-':
            res -= num_list[i + 1]

    return res == 7

def concat(operator_list, num_list):
    res = str(num_list[0])
    for op, num in zip(operator_list, num_list[1:]):
        res += op
        res += str(num)

    return res + "=7"

def solve():
    line = input()
    num_list = []
    for s in line:
        num_list.append(int(s))

    q = queue.Queue()
    q.put([])
    N = len(num_list)
    while not q.empty():
        operator_list = q.get()
        # print(operator_list)
        if len(operator_list) == N - 1:
            if check(operator_list, num_list):
                return concat(operator_list, num_list)

        else:
            q.put(operator_list + [ '+' ])
            q.put(operator_list + [ '-' ])

    return "No Answer"


print(solve())

Submission status: Accepted

Solution code:
def check(operator_list, num_list):
    res = num_list[0]
    for i, op in enumerate(operator_list):
        if op == '+':
            res += num_list[i + 1]
        elif op == '-':
            res -= num_list[i + 1]

    return res == 7

def concat(operator_list, num_list):
    res = str(num_list[0])
    for op, num in zip(operator_list, num_list[1:]):
        res += op
        res += str(num)

    return res + "=7"

def solve():
    line = input()
    num_list = []
    for s in line:
        num_list.append(int(s))

    stack = []
    stack.append([])
    N = len(num_list)
    while len(stack) > 0:
        operator_list = stack.pop()
        # print(operator_list)
        if len(operator_list) == N - 1:
            if check(operator_list, num_list):
                return concat(operator_list, num_list)

        else:
            stack.append(operator_list + [ '+' ])
            stack.append(operator_list + [ '-' ])

    return "No Answer"


print(solve())

Submission status: Accepted

Solution code:
import sys

def check(operate_list, num_list):
    res = num_list[0]
    for i, op in enumerate(operate_list):
        if op == "+":
            res += num_list[i+1]
        elif op == "-":
            res -= num_list[i+1]
    return res == 7

def concat(operate_list, num_list):
    num_list = list(map(str, num_list))
    string = num_list[0]
    for op, num in zip(operate_list, num_list[1:]):
        # it is beautiful!
        string += op
        string += num
    string += "=7"
    return string

def main():
    line = sys.stdin.readline().strip()
    num_list = []
    for s in line:
        num_list.append(int(s))
    result = ""
    stack = []
    stack.append([])
    N = len(num_list)
    while(len(stack) != 0):
        l = stack.pop()
        if len(l) == N-1:
            if check(l, num_list):
                result = concat(l, num_list)
                break
        else:
            stack.append(l + ["+"]) # careful code
            stack.append(l + ["-"])

    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
nums = map(int, list(raw_input()))
ans = None
for op1 in ("+", "-"):
  for op2 in ("+", "-"):
    for op3 in ("+", "-"):
      x = nums[0]
      x += nums[1] * (1 if op1 == "+" else -1)
      x += nums[2] * (1 if op2 == "+" else -1)
      x += nums[3] * (1 if op3 == "+" else -1)
      if x == 7:
        ans = str(nums[0])+op1+str(nums[1])+op2+str(nums[2])+op3+str(nums[3])+"=7"
    if ans:
      break
  if ans:
    break
print ans

Submission status: Accepted

Solution code:
ABCD=input()
def Op_change(a):
  if a==1:
    return "+"
  elif a==-1:
    return "-"
  else:
    return ""
A=int(ABCD[0])
B=int(ABCD[1])
C=int(ABCD[2])
D=int(ABCD[3])
Op=[1,-1]
Op_List=[]
Flag=0
for i in Op:
  for j in Op:
    for k in Op:
      if A+i*B+j*C+k*D==7:
        Flag=1        
        Op_List.append(Op_change(i))
        Op_List.append(Op_change(j))
        Op_List.append(Op_change(k))
        break
    if Flag==1:
      break
  if Flag==1:
      break
print(str(A)+Op_List[0]+str(B)+Op_List[1]+str(C)+Op_List[2]+str(D)+"=7")

Submission status: Accepted

Solution code:
s = input()
abcd = [int(a) for a in s]
flg = 0
for i in range(2**3):
    if flg != 0:
        break
    bin_i = format(i, '03b')
    ops = [int(a)*2-1 for a in bin_i]
    sum = abcd[0]
    for j in range(3):
        sum += ops[j]*abcd[j+1]
        if sum==7:
            flg = 1
            break

ans = s[0]
for j in range(3):
    if ops[j]==1:
        a = '+'
    else:
        a = '-'
    ans += a+s[j+1]
print(ans+'=7')

Submission status: Accepted

Solution code:
N = input()
#A, B, C, D = list(map(int, input().strip().split()))
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])
ans1 = A+B+C+D
ans2 = A+B+C-D
ans3 = A+B-C+D
ans4 = A+B-C-D
ans5 = A-B+C+D
ans6 = A-B+C-D
ans7 = A-B-C+D
ans8 = A-B-C-D

if ans1 == 7:
	print('%d+%d+%d+%d=7' % (A, B, C, D))
elif ans2 == 7:
	print('%d+%d+%d-%d=7' % (A, B, C, D))
elif ans3 == 7:
	print('%d+%d-%d+%d=7' % (A, B, C, D))
elif ans4 == 7:
	print('%d+%d-%d-%d=7' % (A, B, C, D))
elif ans5 == 7:
	print('%d-%d+%d+%d=7' % (A, B, C, D))
elif ans6 == 7:
	print('%d-%d+%d-%d=7' % (A, B, C, D))
elif ans7 == 7:
	print('%d-%d-%d+%d=7' % (A, B, C, D))
else:
	print('%d-%d-%d-%d=7' % (A, B, C, D))

Submission status: Accepted

Solution code:
from itertools import zip_longest

abcd = input()

for i in range(0, 8):
	signs = bin(i)[2:].zfill(3).replace("1", "+").replace("0", "-")
	formula = "".join("".join(s) for s in zip_longest(abcd, signs, fillvalue=""))
	if eval(formula) == 7:
		print(formula+"=7")
		exit()

Submission status: Accepted

Solution code:
N = input()
A = N[0]
B = N[1]
C = N[2]
D = N[3]

op = ('+', '-')

flag = False
for op1 in op:
    for op2 in op:
        for op3 in op:
           if eval(A+op1+B+op2+C+op3+D) == 7:
                flag = True
                break
        if flag: break
    if flag: break

print(A+op1+B+op2+C+op3+D+'=7')

Submission status: Accepted

Solution code:
def dfs(i,total,s=""):
    if i == 3:
        if total == 7:
            return s
        else:
            return False

    s += "+"
    ans = dfs(i+1, total+l[i+1], s)
    if ans:
        return ans

    s = s[:-1]
    s += "-"
    ans = dfs(i+1, total-l[i+1], s)
    if ans:
        return ans


l = list(map(int,input()))
operation = dfs(0,l[0])
result = ""

for i in range(3):
    result += str(l[i]) + operation[i]
print(result + str(l[3]) + "=7")

Submission status: Accepted

Solution code:
a,b,c,d = list(map(int,list(input())))
ans = []
if a+b+c+d == 7:
    ans = ['+','+','+']
elif a+b+c-d == 7:
    ans = ['+','+','-']
elif a+b-c-d == 7:
    ans = ['+','-','-']
elif a+b-c+d == 7:
    ans = ['+','-','+']
elif a-b+c-d == 7:
    ans = ['-','+','-']
elif a-b-c-d == 7:
    ans = ['-','-','-']
elif a-b-c+d == 7:
    ans = ['-','-','+']
else:
    ans = ['-','+','+']

print('{}{}{}{}{}{}{}=7'.format(a,ans[0],b,ans[1],c,ans[2],d))

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input())
s=[1,-1]
f=['+','-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+b*s[i]+c*s[j]+d*s[k]==7:
                    print(str(a)+f[i]+str(b)+f[j]+str(c)+f[k]+str(d)+'=7')
                    exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# input
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
# calc
op = ["+", "-"]
for i in range(2):
    ans = a
    if i == 0:
        ans += b
    else:
        ans -= b
    ans1 = ans
    for j in range(2):
        ans = ans1
        if j == 0:
            ans += c
        else:
            ans -= c
        ans2 = ans
        for k in range(2):
            ans = ans2
            if k == 0:
                ans += d
            else:
                ans -= d
            if ans == 7:
                print(str(a) + op[i] + str(b) + op[j] + str(c) + op[k] + str(d) + "=7")
                sys.exit()
# output
# 答えが存在しない入力は与えられない

Submission status: Accepted

Solution code:
n = list(raw_input())
op = ['+', '-']

for o1 in op:
  for o2 in op:
    for o3 in op:
      s = n[0] + o1 + n[1] + o2 + n[2] + o3 + n[3]
      if eval(s) == 7:
        print s + '=7'
        exit(0)

Submission status: Accepted

Solution code:
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

if A+B+C+D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C-D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

Submission status: Accepted

Solution code:
# encoding: utf-8
A, B, C, D = map(int, input())

for i in range(8):
    opB = 2 * int(i & 1 > 0) - 1
    opC = 2 * int(i & 2 > 0) - 1
    opD = 2 * int(i & 4 > 0) - 1
    if A + opB * B + opC * C + opD * D == 7: break

ans = str(A)
for opX, X in [(opB, str(B)), (opC, str(C)), (opD, str(D))]:
    ans += "+" if opX > 0 else "-"
    ans += X
ans += "=7"

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3                                                                                                                                                                                          

import itertools

if __name__=='__main__':
    str = input()
    signs_comb = list(itertools.product([1, -1], repeat=3))
    for signs in signs_comb:
        sum = int(str[0])
        for i in range(3):
            sum += signs[i] * int(str[i + 1])
        if sum == 7:
            sign_char = ['+' if i==1 else '-' for i in signs]
            break
    exp = str[0] + sign_char[0] + str[1] + sign_char[1] + str[2] + sign_char[2] + str[3] + '=7'
    print(exp)

Submission status: Accepted

Solution code:
N = input()
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
if a+b+c+d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Submission status: Accepted

Solution code:
def solve(ABCD):
    for i in range(0, 8):
        ops = "{:03b}".format(i)
        op1 = "+" if ops[0] == "0" else "-"
        op2 = "+" if ops[1] == "0" else "-"
        op3 = "+" if ops[2] == "0" else "-"
        s = ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3]
        if eval(s) == 7:
            return s + "=7"
    return "error"


if __name__ == "__main__":
    ABCD = input()
    print(solve(ABCD))

Submission status: Accepted

Solution code:
x = list(map(int, list(input())))
y = [0] * 4
for i in range(8):
    y[0] = x[0]
    s = y[0]
    p = list(map(int, list(format(i, '03b'))))
    for j in range(3):
        y[j + 1] = (2 * p[j] - 1) * x[j + 1]
        s += y[j + 1]
    if s == 7:
        print('{}{:+d}{:+d}{:+d}=7'.format(y[0], y[1], y[2], y[3]))
        exit()

Submission status: Accepted

Solution code:
def 解():
    aD = [int(_) for _ in list(input().rstrip())]
    iA = 2**3
    for i in range(iA):
        iR = aD[0]
        for j in range(3):
            if i & (1 << j) :
                iR += aD[j+1]
            else:
                iR -= aD[j+1]
        if iR == 7:
            sR = str(aD[0])
            def buildSS(b):
                if b :
                    return "+"
                else:
                    return "-"
            for j in range(3):
                sR = "".join((sR,buildSS(i&(1<<j)),str(aD[j+1])))
            print("".join((sR,"=7")))
            exit()

解()

Submission status: Accepted

Solution code:
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

if a+b+c+d == 7:
  print('%d+%d+%d+%d=7' % (a, b, c, d))
elif a+b+c-d == 7:
  print('%d+%d+%d-%d=7' % (a, b, c, d))
elif a+b-c+d == 7:
  print('%d+%d-%d+%d=7' % (a, b, c, d))
elif a+b-c-d == 7:
  print('%d+%d-%d-%d=7' % (a, b, c, d))
elif a-b+c+d == 7:
  print('%d-%d+%d+%d=7' % (a, b, c, d))
elif a-b+c-d == 7:
  print('%d-%d+%d-%d=7' % (a, b, c, d))
elif a-b-c+d == 7:
  print('%d-%d-%d+%d=7' % (a, b, c, d))
elif a-b-c-d == 7:
  print('%d-%d-%d-%d=7' % (a, b, c, d))

Submission status: Accepted

Solution code:
A, B, C, D = map(int, list(input()))

f = True

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            if f == True:
                R = 0
                r = ''
                if op1 == 0:
                    R = A + B
                    r = '%s+%s' % (A, B)
                else:
                    R = A - B
                    r = '%s-%s' % (A, B)
                if op2 == 0:
                    R += C
                    r = '%s+%s' % (r, C)
                else:
                    R -= C
                    r = '%s-%s' % (r, C)
                if op3 == 0:
                    R += D
                    r = '%s+%s' % (r, D)
                else:
                    R -= D
                    r = '%s-%s' % (r, D)
                if R == 7:
                    print('%s=7' % r)
                    f = False

Submission status: Accepted

Solution code:
(a, b, c, d) = map(int, list(input()))

if a+b+c+d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b+c-d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a+b-c+d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b+c+d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b-c-d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
elif a-b+c-d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a-b-c+d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b-c-d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')

Submission status: Accepted

Solution code:
S = input()
s = list(S)
nums = []
for i in s:
    nums.append(int(i))

sum = nums[0]
ans = ""
a = ""
check = False
for i in range(2):
    if check:
        break
    else:
        sum = nums[0]
        ans = s[0]
    if i == 0:
        sum += nums[1]
        ans += "+"
    else:
        sum -= nums[1]
        ans += "-"
    ans += s[1]
    for j in range(2):
        sum2 = sum
        ans2 = ans
        if j == 0:
            sum2 += nums[2]
            ans2 += "+"
        else:
            sum2 -= nums[2]
            ans2 += "-"
        ans2 += s[2]
        for k in range(2):
            sum3 = sum2
            ans3 = ans2
            if k == 0:
                sum3 += nums[3]
                ans3 += "+"
            else:
                sum3 -= nums[3]
                ans3 += "-"
            ans3 += s[3]
            if sum3 == 7:
                check = True
                a = ans3
a += "=7"
print(a)

Submission status: Accepted

Solution code:
n = list(input())
for i in range(8):
    ans = n[0]
    ans += '+-'[i%2] + n[1]
    ans += '+-'[i//4] + n[2]
    ans += '+-'[(i%4)//2] + n[3]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Submission status: Accepted

Solution code:

ABCD=list(map(int,list(input())))

n=8
bit=0
while(bit<n):
    tmp=ABCD[0]
    for i in range(0,3):
        if(bit & 1<<i):
            tmp+=ABCD[i+1]
        else:
            tmp-=ABCD[i+1]
    if(tmp==7):
        break
    else:
        bit+=1

print(ABCD[0],end="")
for i in range(0,3):
    if(bit & 1<<i):
        print("+{}".format(ABCD[i+1]),end="")
    else:
        print("-{}".format(ABCD[i+1]),end="")        
print("=7")

Submission status: Accepted

Solution code:
A, B, C, D = input()

op = ['+', '-']

for i in op:
    for j in op:
        for k in op:
            f = A + i + B + j + C + k + D
            if eval(f) == 7:
                print(f + '=7')
                exit()