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:
N = input()
A, B, C, D = [int(i) for i in N]

def judge(a, b, c, d):
  if a + b + c + d == 7:
    return '{}+{}+{}+{}=7'.format(a, b, c, d)
  elif a - b - c - d == 7:
    return '{}-{}-{}-{}=7'.format(a, b, c, d)
  elif a + b - c - d == 7:
    return '{}+{}-{}-{}=7'.format(a, b, c, d)
  elif a - b + c - d == 7:
    return '{}-{}+{}-{}=7'.format(a, b, c, d)
  elif a - b - c + d == 7:
    return '{}-{}-{}+{}=7'.format(a, b, c, d)
  elif a - b + c + d == 7:
    return '{}-{}+{}+{}=7'.format(a, b, c, d)
  elif a + b + c - d == 7:
    return '{}+{}+{}-{}=7'.format(a, b, c, d)
  elif a + b - c + d == 7:
    return '{}+{}-{}+{}=7'.format(a, b, c, d)

print(judge(A, B, C, D))

Submission status: Accepted

Solution code:
s = input()
exp = []

def dfs(pos, tot):
    global exp
    if pos == 3:
        return tot == 7

    exp.append("+")
    if dfs(pos + 1, tot + int(s[pos+1])):
        return True
    exp.pop()
    exp.append("-")
    if dfs(pos + 1, tot - int(s[pos+1])):
        return True
    exp.pop()

def main():
    ok = 0
    if dfs(0, int(s[0])):
        for c, i in zip(s, exp):
            print(c, end="")
            print(i, end="")
        print(s[3] + "=7")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ABCD = [int(x) for x in list(input())]

calc_seq = [ABCD[0]]
op_seq = []

for i in range(1,4):
    for h in calc_seq[(2**(i-1))-1:(2**(i))-1]:
        calc_seq.append(h - ABCD[i])
        calc_seq.append(h + ABCD[i])

for i in range(7,16):
    if calc_seq[i] == 7:
        while i != 0:
            if i % 2 == 0:
                op_seq.append("+")
            else:
                op_seq.append("-")
            i = (i - 1) // 2
        break

op_seq = op_seq[::-1]
print(str(ABCD[0]) + op_seq[0] + str(ABCD[1]) + op_seq[1] + str(ABCD[2]) + op_seq[2] + str(ABCD[3]) + "=7")

Submission status: Accepted

Solution code:
s = raw_input()
for e in [s[0] + x + s[1] + y + s[2] + z + s[3] for x in '+-' for y in '+-' for z in '+-']:
    if eval(e) == 7:
        print e + '=7'
        exit()

Submission status: Accepted

Solution code:
A,B,C,D=map(int,list(input()))
o=["+","-"]
if A+B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[0])
elif A+B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[0],o[1])
elif A+B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[0])
elif A+B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[0],o[1],o[1])
elif A-B+C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[0])
elif A-B+C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[0],o[1])
elif A-B-C+D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[0])
elif A-B-C-D==7:
    strings="A{}B{}C{}D=7".format(o[1],o[1],o[1])
strings=list(strings)
strings[0]=str(A)
strings[2]=str(B)
strings[4]=str(C)
strings[6]=str(D)
print("".join(strings))

Submission status: Accepted

Solution code:
#ABC079C

a,b,c,d=map(int,raw_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:
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:
# coding: utf-8

s = raw_input()

for op1 in "+-":
    for op2 in "+-":
        for op3 in "+-":
            e = s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3]
            if eval(e) == 7:
                print e + "=7"
                exit(0)

Submission status: Accepted

Solution code:
T = list(map(int, list(input())))

def search(ops, p):
    if p < 3:
        ops[p] = 1
        ret_ops = search(ops, p+1)
        if T[p+1] == 0 or sum(T[0:1] + [t * op for (t, op) in zip(T[1:], ret_ops)]) == 7:
            return ret_ops
        else:
            ops[p] = -1
            return search(ops, p+1)
    else:
        return ops

ops = search([None, None, None], 0)

T = list(map(str, T))
ops = ["+" if op == 1 else "-" for op in ops]
print("{}{}=7".format(T[0], "".join(map(lambda x: "".join(x), zip(ops, T[1:])))))

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('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a-b+c+d == 7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Submission status: Accepted

Solution code:
l = list(input()) 
for i in range(8):
    p = ["+"if i&j else"-" for j in[1, 2, 4]]
    line = "".join([v+o for v,o in zip(l,p)]) + l[3]
    if eval(line) == 7:
        print(line + "=7")
        break

Submission status: Accepted

Solution code:
l = list(input()) 
for i in range(8):
    p = ["+"if i&j else"-" for j in[1, 2, 4]]
    line = "".join([v+o for v,o in zip(l,p)])
    line += l[3]
    if eval(line) == 7:
        print(line + "=7")
        break

Submission status: Accepted

Solution code:
from itertools import zip_longest

l = list(input()) 
for i in range(8):
    p = ["+"if i & j else"-" for j in[1, 2, 4]]
    p.append("")
    line = "".join([v+o for v,o in zip_longest(l,p)])
    if eval(line) == 7:
        print(line + "=7")
        break

Submission status: Accepted

Solution code:
a, b, c, d = [int(i) for i in input()]
for i in range(8):
    p = ["+"if i & j else"-" for j in[1, 2, 4]]
    line = "{0}{1}{2}{3}{4}{5}{6}".format(a, p[0], b, p[1], c, p[2], d)
    if eval(line) == 7:
        print(line + "=7")
        break

Submission status: Accepted

Solution code:
a,b,c,d = [int(i) for i in input()]
for i in range(8):
  pattern = []
  for j in [1,2,4]:
    pattern.append("+"if i&j else"-")
  line = "{0}{1}{2}{3}{4}{5}{6}".format(a,pattern[0],b,pattern[1],c,pattern[2],d)
  if eval(line) == 7:
    print(line + "=7")
    break

Submission status: Accepted

Solution code:
n=list(input())
op="+----"
for i in range(8):
    s=n[0]+op[i&4]+n[1]+op[i&2]+n[2]+op[i&1]+n[3]
    if eval(s)==7:
        print(s+"=7")
        break;

Submission status: Accepted

Solution code:
import sys

N = input()

A=int(N[0])
B=int(N[1])
C=int(N[2])
D=int(N[3])

def myprint(lst):
	s=str(A)+lst[0]+str(B)+lst[1]+str(C)+lst[2]+str(D)+"=7"
	print(s)


def calc2(a,b,op):
	if(op=="-"):
		return a-b
	else:
		return a+b

def calc(lst):
	sum=calc2(calc2(calc2(A,B,lst[0]),C,lst[1]),D,lst[2])
	return sum


lst=["+","+","+"]

lst2=0
while(True):
	if(calc(lst)==7):
		myprint(lst)
		break
	lst2+=1
	temp=format(lst2,"03b")
	for i in range(3):
		if(temp[i]=="0"):
			lst[2-i]="-"
		else:
			lst[2-i]="+"

Submission status: Accepted

Solution code:
a=list(raw_input())
b=[]
for i in a:
    b.append(int(i))
for i in range(1):
    if b[0]+b[1]+b[2]+b[3]==7:
        c=[0,0,0]
        break
    elif b[0]+b[1]+b[2]-b[3]==7:
        c=[0,0,1]
        break
    elif b[0]+b[1]-b[2]+b[3]==7:
        c=[0,1,0]
        break
    elif b[0]+b[1]-b[2]-b[3]==7:
        c=[0,1,1]
        break
    elif b[0]-b[1]+b[2]+b[3]==7:
        c=[1,0,0]
        break
    elif b[0]-b[1]+b[2]-b[3]==7:
        c=[1,0,1]
        break
    elif b[0]-b[1]-b[2]+b[3]==7:
        c=[1,1,0]
        break
    elif b[0]-b[1]-b[2]-b[3]==7:
        c=[1,1,1]
        break
ans=""
c.append("=7")
for i in range(4):
    ans+=a[i]
    if c[i]==0:
        ans+="+"
    elif c[i]==1:
        ans+="-"
    else:
        ans+=c[i]
print ans

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:
N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])
A = N[0]
B = N[1]
C = N[2]
D = N[3]

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

s = input()

for op in itertools.product("+-", repeat=3) :
    exp = "".join(i+j for i,j in zip(s,list(op)+['=']))
    val = eval(exp[0:-1])
    if val == 7 :
        print(exp + '7')
        exit(0)

Submission status: Accepted

Solution code:
import itertools

s = input()

for op in itertools.product("+-", repeat=3) :
    exp = s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]
    val = eval(exp)
    if val == 7 :
        print(exp + '=7')
        exit(0)

Submission status: Accepted

Solution code:
s = list(raw_input())
for op1 in '+-':
    for op2 in '+-':
        for op3 in '+-':
            exec 'ans=%s%s%s%s%s%s%s' % (s[0], op1, s[1], op2, s[2], op3, s[3])
            if ans == 7:
                print '%s%s%s%s%s%s%s=7' % (s[0], op1, s[1], op2, s[2], op3, s[3])
                exit()

Submission status: Accepted

Solution code:
def main():
    ABCD = list(input())
    A = int(ABCD[0])
    B = int(ABCD[1])
    C = int(ABCD[2])
    D = int(ABCD[3])

    flag = True
    for i in ['+', '-']:
        if flag:
            sumAB = A + B if i == '+' else A - B
            for j in ['+', '-']:
                if flag:
                    sumABC = sumAB + C if j == '+' else sumAB - C
                    for k in ['+', '-']:
                        if flag:
                            sumABCD = sumABC + D if k == '+' else sumABC - D
                            if sumABCD == 7:
                                print(str(A) + i + str(B) + j + str(C) + k + str(D) + "=7")
                                flag = False

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
ABCD = str, input()
ABCD_list = list(ABCD[1])
A = int(ABCD_list[0])
B = int(ABCD_list[1])
C = int(ABCD_list[2])
D = int(ABCD_list[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:
# coding: utf-8
N=input()
lst=list(N)
#+++
if (int(lst[0])+int(lst[1])+int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'+'+lst[2]+'+'+lst[3]+'=7')
#---
elif (int(lst[0])-int(lst[1])-int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'-'+lst[2]+'-'+lst[3]+'=7')
#-+-    
elif (int(lst[0])-int(lst[1])+int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'+'+lst[2]+'-'+lst[3]+'=7')
#+-+    
elif (int(lst[0])+int(lst[1])-int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'-'+lst[2]+'+'+lst[3]+'=7')

#++-
elif (int(lst[0])+int(lst[1])+int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'+'+lst[2]+'-'+lst[3]+'=7')
#+--    
elif (int(lst[0])+int(lst[1])-int(lst[2])-int(lst[3]))==7:
    print(lst[0]+'+'+lst[1]+'-'+lst[2]+'-'+lst[3]+'=7')
#-++    
elif (int(lst[0])-int(lst[1])+int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'+'+lst[2]+'+'+lst[3]+'=7')
#--+   
elif (int(lst[0])-int(lst[1])-int(lst[2])+int(lst[3]))==7:
    print(lst[0]+'-'+lst[1]+'-'+lst[2]+'+'+lst[3]+'=7')

Submission status: Accepted

Solution code:
N = raw_input()
keys = ['+','-']
x = 0
check = True
ans = ''
for key1 in keys:
    if key1 == '+' and check:
        x1 = int(N[0]) + int(N[1])
    elif(key1 == '-' and check):
        x1 = int(N[0]) - int(N[1])
    for key2 in keys:
        if key2 == '+' and check:
            x2 = x1  + int(N[2])
        elif(key2 == '-' and check):
            x2 = x1  - int(N[2])
        
        #print x
        for key3 in keys:
            if key3 == '+' and check:
                #print x
                #print int(N[3])
                x3 = x2  + int(N[3])
                #print x
                if (x3 == 7):
                    ans = N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False


            elif(key3 == '-' and check):

                x3 = x2  - int(N[3])

                if (x3 == 7):
                    ans =  N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False

            #print x
print ans

Submission status: Accepted

Solution code:
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

num = int(raw_input())

p_dbg('num : ' + str(num))

array = []
# set to array by 10
dig = 4
while dig > 0:
    array.append((num % 10))
    num = num / 10
    dig = dig -1

array.reverse()
p_dbg('array : ' + str(array))

def ope_permutation(ope_array):
    ope1 = []
    ope2 = []
    ope3 = []
    ope1[:]=ope_array
    ope2[:]=ope_array
    ope3[:]=ope_array
    perm = []
    for o1 in ope1:
        for o2 in ope2:
            for o3 in ope3:
                perm.append([o1, o2, o3])

    return perm

ope_perm = ope_permutation(['+','-'])
p_dbg('ope_perm'+str(ope_perm))

for perm in ope_perm:
    sig = [1,1,1]
    if perm[0] == '-':
        sig[0] = -1
    else:
        sig[0] = 1
    if perm[1] == '-':
        sig[1] = -1
    else:
        sig[1] = 1
    if perm[2] == '-':
        sig[2] = -1
    else:
        sig[2] = 1
    if array[0] + sig[0]* array[1] + sig[1]* array[2] + sig[2]* array[3] == 7:
        print str(array[0]) + perm[0] + str(array[1]) + perm[1] + str(array[2]) + perm[2] + str(array[3])+'=7'
        break

Submission status: Accepted

Solution code:
#coding: utf-8
N = input()
N_list = list(map(int,N))
N_str = str(N)

if   (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Submission status: Accepted

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
a,b,c,d = s[0],s[1],s[2],s[3]

def calc(i,j,k):
    if i == 0:
        i = 1
    else:
        i = -1
    if j == 0:
        j = 1
    else:
        j = -1
    if k == 0:
        k = 1
    else:
        k = -1       
    return int(a) + int(b)*i + int(c)*j + int(d)*k,i,j,k

def pm(s):
    if s == 0:
        return "+"
    else:
        return "-"
    
for i in range(2):
    for j in range(2):
        for k in range(2):
            if calc(i,j,k)[0] == 7:
                print(a+pm(i)+b+pm(j)+c+pm(k)+d+"=7")
                exit()

Submission status: Accepted

Solution code:
#!/user/bin/python
# coding: UTF-8
import sys

x = str(raw_input())
x_list = list(x)
x_int = []

for i in range(len(x_list)):
    x_int.append(int(x_list[i]))

if x_int[0] + x_int[1] + x_int[2] + x_int[3] == 7:
    op = ['+', '+', '+']
elif x_int[0] + x_int[1] + x_int[2] - x_int[3] == 7:
    op = ['+', '+', '-']
elif x_int[0] + x_int[1] - x_int[2] + x_int[3] == 7:
    op = ['+', '-', '+']
elif x_int[0] + x_int[1] - x_int[2] - x_int[3] == 7:
    op = ['+', '-', '-']
elif x_int[0] - x_int[1] + x_int[2] + x_int[3] == 7:
    op = ['-', '+', '+']
elif x_int[0] - x_int[1] + x_int[2] - x_int[3] == 7:
    op = ['-', '+', '-']
elif x_int[0] - x_int[1] - x_int[2] + x_int[3] == 7:
    op = ['-', '-', '+']
elif x_int[0] - x_int[1] - x_int[2] - x_int[3] == 7:
    op = ['-', '-', '-']

sys.stdout.write(x_list[0])
sys.stdout.write(op[0])
sys.stdout.write(x_list[1])
sys.stdout.write(op[1])
sys.stdout.write(x_list[2])
sys.stdout.write(op[2])
sys.stdout.write(x_list[3])
sys.stdout.write('=7')

Submission status: Accepted

Solution code:
#coding: utf-8
N = input()
N_list = list(map(int,N))
N_str = str(N)

if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Submission status: Accepted

Solution code:

def solve(A,op):
    result=[0]*4
    result[0]=A[0]
    for i in range(2):
        if i==0:
            result[1]=result[0]+A[1]
            op[0]="+"
        else:
            result[1]=result[0]-A[1]
            op[0]="-"
        for j in range(2):
            if j==0:
                result[2] = result[1]+A[2]
                op[1]="+"
            else:
                result[2] = result[1]-A[2]
                op[1]="-"
            for k in range(2):
                if k==0:
                    result[3] = result[2]+A[3]
                    op[2]="+"
                else:
                    result[3] = result[2]-A[3]
                    op[2]="-"
                #print("{}{}{}{}{}{}{}?7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                #print(result[3])
                if result[3]==7:
                    print("{}{}{}{}{}{}{}=7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                    return

def main():
    A=[0]*4
    op=[""]*3
    A=list(map(int,input()))
    solve(A,op)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    op = '+-'
    s = input()

    for x in op:
        for y in op:
            for z in op:
                t = s[0] + x + s[1] + y + s[2] + z + s[3]
                if eval(t) == 7:
                    return t + '=7'

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
#coding: utf-8
N = input()
N_list = list(map(int,N))
N_str = str(N)

if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3])==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Submission status: Accepted

Solution code:
sr = input()

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

def calc(one, two, three):
  if a + one*b + two*c + three*d == 7:
    return True
  else:
    return False
  
def change(num):
  if num == 1:
    return "+"
  else:
    return "-"
  
flag = False
for q in [1, -1]:
  for w in [1, -1]:
    for e in [1, -1]:
      if calc(q, w, e):
        r, t, y = change(q), change(w), change(e)
        print(str(a)+r+str(b)+t+str(c)+y+str(d)+"=7")
        flag = True
        break
    if flag:
      break
  if flag:
    break

Submission status: Accepted

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

if a[0]+a[1]+a[2]+a[3] == 7:
  print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]+a[2]+a[3] == 7:
  print("{0}-{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]-a[2]+a[3] == 7:
  print("{0}+{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]+a[2]-a[3] == 7:
  print("{0}+{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]-a[2]+a[3] == 7:
  print("{0}-{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]+a[2]-a[3] == 7:
  print("{0}-{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]-a[2]-a[3] == 7:
  print("{0}+{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]-a[2]-a[3] == 7:
  print("{0}-{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()

Submission status: Accepted

Solution code:
n = input()
num = [int(n[0]), int(n[1]), int(n[2]), int(n[3])]
if sum(num) == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")

Submission status: Accepted

Solution code:


def ans(x1, x2, x3, x4, state1, state2, state3):
    return int(eval("{}{}{}{}{}{}{}".format(x1,state1,x2,state2,x3,state3,x4)))

n = input()

x1 = int(n[0])
x2 = int(n[1])
x3 = int(n[2])
x4 = int(n[3])

state1 = "+"
state2 = "+"
state3 = "+"

x = 7

for n in range(8):
    if n == 0:
        k = "000"
    if n == 1:
        k = "001"
    if n == 2:
        k = "010"
    if n == 3:
        k = "011"
    if n == 4:
        k = "100"
    if n == 5:
        k = "101"
    if n == 6:
        k = "110"
    if n == 7:
        k = "111"
    
    if k[0] == "0":
        state1 = "+"
    else:
        state1 = "-"
    try:
        if k[1] == "0":
            state2 = "+"
        else:
            state2 = "-"
    except:
        state2 = "+"
    try:
        if k[2] == "0":
            state3 = "+"
        else:
            state3 = "-"
    except:
        state3 = "+"
    a = ans(x1, x2,x3,x4,state1,state2,state3)
    if a == 7:
        break
print("{}{}{}{}{}{}{}=7".format(x1,state1,x2,state2,x3,state3,x4))

Submission status: Accepted

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

if a+b+c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a+b+c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a+b-c+d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
elif a+b-c-d ==7:
  sys.stdout.write(r[0]+"+"+r[1]+"-"+r[2]+"-"+r[3]+"=7")
elif a-b+c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"+"+r[3]+"=7")
elif a-b+c-d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"+"+r[2]+"-"+r[3]+"=7")
elif a-b-c+d ==7:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"+"+r[3]+"=7")
else:
  sys.stdout.write(r[0]+"-"+r[1]+"-"+r[2]+"-"+r[3]+"=7")

Submission status: Accepted

Solution code:
#!/usr/bin/python

from sys import stdin

def eval(ds, ops):
  e = ds[0]
  for i in range(1, len(ds)):
    e = e + (ds[i] if ops[i - 1] == '+' else -ds[i])
  return e

def solve(ds):
  ops = ['+', '-']
  for op1 in ops:
    for op2 in ops:
      for op3 in ops:
        if eval(ds, [op1, op2, op3]) == 7:
          return str(ds[0])+op1+str(ds[1])+op2+str(ds[2])+op3+str(ds[3])+"=7"

ABCD = stdin.readline().strip()
ds = [int(ABCD[i]) for i in range(len(ABCD))]
print(solve(ds))

Submission status: Accepted

Solution code:
# coding: utf-8
n = list(map(int,input()))

if   n[0]+n[1]+n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]+n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")

elif n[0]+n[1]-n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]-n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")

elif n[0]-n[1]+n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]+n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")

elif n[0]-n[1]-n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]-n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

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

cand = [(nums[0], [str(nums[0])])]

for num in nums[1:]:
    new_cand = []
    for s, signs in cand:
        new_cand.append((s + num, signs + ['+', str(num)]))
        new_cand.append((s - num, signs + ['-', str(num)]))
    cand = new_cand

for num, signs in cand:
    if num == 7:
        print(''.join(signs) + '=7')
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(raw_input())
a = n/1000
b = n/100%10
c = n/10%10
d = n%10

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 my_cal(N1,N2,PM):
    if PM == "+":
        return N1+N2
    else:
        return N1-N2
    
if __name__ == '__main__':
    I = list(map(int,input()))
    ANS = []
    for ele1 in ["+","-"]:
         for ele2 in ["+","-"]:
                for ele3 in ["+","-"]:
                     if my_cal(my_cal(my_cal(I[0],I[1],ele1),I[2],ele2),I[3],ele3) == 7:
                            ANS.append(str(I[0])+ele1+str(I[1])+ele2+str(I[2])+ele3+str(I[3])+"=7")
    print(ANS[0])