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:
x=input()
a=x[0]
b=x[1]
c=x[2]
d=x[3]

for i in range(8):
  bi=bin(i)[2:].zfill(3)
  temp=[]
  for j in range(3):
    if bi[j]=="0":
      temp.append("-")
    else:
      temp.append("+")
  ans=""
  for j,k in zip(x,temp):
    ans+=j+k
  ans+=d
  if eval(ans)==7:
    print(ans+"=7")
    exit()

Submission status: Accepted

Solution code:
s_ori = input()
s = [int(c) for c in s_ori]
n = len(s) - 1
for bit in range(2**n):
    total = s[0]
    for i in range(n):
        if (1 << i) & bit:
            total += s[i+1]
        else:
            total -= s[i+1]
    if total == 7:
        break

ans = ''
for i in range(n):
    if bit & (1<<i):
        ans += s_ori[i] + '+'
    else:
        ans += s_ori[i] + '-'

ans += s_ori[-1] + '=7'

print(ans)

Submission status: Accepted

Solution code:
s = input()

num = [0,0,0,0]
num[0], num[1], num[2], num[3] = map(int,(s[0], s[1], s[2], s[3]))

def ope(x):
	if x == 1:
		return '+'
	elif x == 0:
		return '-'
for i in range(8):
	tmp = num[0]
	for j in range(3):
		if (i>>j) & 1:
			tmp += num[j+1]
		else:
			tmp -= num[j+1]
	if tmp == 7:
		print(s[0]+ope(i&1)+s[1]+ope((i>>1)&1)+s[2]+ope((i>>2)&1)+s[3]+'=7')
		break

Submission status: Accepted

Solution code:
s = input()
li = list(map(int,list(s)))

for i in range(8):
  tmp = list(map(int,list(format(i,"03b"))))
  tmp7 = li[0]
  for j in range(3):
    if tmp[j] == 0:
      tmp7 += li[j+1]
    else:
      tmp7 -= li[j+1]
  if tmp7 == 7:
    ans = str(li[0])
    if tmp[0] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[1])
    if tmp[1] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[2])
    if tmp[2] == 0:
      ans += "+"
    else:
      ans += "-"
    ans += str(li[3])
    ans += "=7"
    print(ans)
    exit()

Submission status: Accepted

Solution code:
# dfs
def search7(i, ticket, equation):
    if i == len(ticket) - 1:
        if eval(equation) == 7:
            return True, equation
        else:
            return False, '_'
    else:
        check_param, new_equation = search7(i + 1, ticket, equation + '+' + ticket[i + 1])
        if check_param:
            return True, new_equation
        check_param, new_equation = search7(i + 1, ticket, equation + '-' + ticket[i + 1])
        if check_param:
            return True, new_equation
        
        return False, '_'


def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    ticket = list(input())

    _, equation = search7(0, ticket, ticket[0])
    print(equation+'=7')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
 
for bit in range(1 << 3):
  answer = int(s[0])
  f = s[0] 
  
  for i in range(3):
    if bit & (1 << i):
      f+='+'
      answer+=int(s[i+1])
    else:
      f+='-'
      answer-=int(s[i+1])
    f+=s[i+1]
 
  if answer==7:
    print(f + '=7')
    exit()

Submission status: Accepted

Solution code:
num = list(str(input()))
n = len(num)
for i in range(1 << 3):
    li = [int(num[0])]
    pri = [num[0]]
    for j in range(n - 1):
        if (i >> j) & 1:
            li.append(int(num[j + 1]))
            pri.append("+"+num[j + 1])
        else:
            li.append(-1 * int(num[j + 1]))
            pri.append("-"+num[j + 1])
    if sum(li) == 7:
        print("{}{}{}{}=7".format(pri[0], pri[1], pri[2], pri[3]))
        quit()

Submission status: Accepted

Solution code:
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + "=7")
        exit()

Submission status: Accepted

Solution code:
li=list(input())
A=int(li[0])
B=int(li[1])
C=int(li[2])
D=int(li[3])
if A+B+C+D==7:
  print(li[0]+'+'+li[1]+'+'+li[2]+'+'+li[3]+'=7')
  
elif A+B+C-D==7:
  print(li[0]+'+'+li[1]+'+'+li[2]+'-'+li[3]+'=7')
  
elif A+B-C+D==7:
  print(li[0]+'+'+li[1]+'-'+li[2]+'+'+li[3]+'=7')

elif A+B-C-D==7:
  print(li[0]+'+'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

elif A-B+C+D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'+'+li[3]+'=7')
  
elif A-B+C-D==7:
  print(li[0]+'-'+li[1]+'+'+li[2]+'-'+li[3]+'=7')
  
elif A-B-C+D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'+'+li[3]+'=7')

elif A-B-C-D==7:
  print(li[0]+'-'+li[1]+'-'+li[2]+'-'+li[3]+'=7')

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(input()))
for i in range(8):
    ans = a
    tb = b
    tc = c
    td = d
    op = format(i, "b").zfill(3)
    if op[0] == "1":
        tb = -tb
    if op[1] == "1":
        tc = -tc
    if op[2] == "1":
        td = -td
    ans += tb + tc + td
    if ans == 7:
        break
op = op.replace("0", "+").replace("1", "-") + "_"
s = ""
for n, o in zip([a, b, c, d], op):
    s += str(n) + o
print(s[:-1] + "=7")

Submission status: Accepted

Solution code:
#ABC079C - Train Ticket
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))

s = list(str(input()))

dfs(0, s[0], int(s[0]))

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
S=input()
sign="+-"
for i in range(2):
  for j in range(2):
    for n in range(2):
      if eval(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])==7:
        print(str(S[0]+sign[i]+S[1]+sign[j]+S[2]+sign[n]+S[3])+'=7')
        exit()

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
X=list(input())
A,B,C,D=map(int,X)
if A+B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'+'+D+'=7')
  exit()
elif A+B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'+'+C+'-'+D+'=7')
  exit()
elif A+B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'+'+D+'=7')
  exit()
elif A-B+C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'+'+D+'=7')
  exit()
elif A-B-C+D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'+'+D+'=7')
  exit()
elif A+B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'+'+B+'-'+C+'-'+D+'=7')
  exit()
elif A-B+C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'+'+C+'-'+D+'=7')
  exit()
elif A-B-C-D==7:
  A=str(A)
  B=str(B)
  C=str(C)
  D=str(D)
  print(A+'-'+B+'-'+C+'-'+D+'=7')
  exit()
else:
  print('None')

Submission status: Accepted

Solution code:
def c():
    li = list(input())
    syms = ['+', '-']
    calc = li[0]
    for i in range(2):
        i_calc = calc
        calc += syms[i] + li[1]
        for j in range(2):
            j_calc = calc
            calc += syms[j] + li[2]
            for k in range(2):
                k_calc = calc
                calc += syms[k] + li[3]
                res = eval(calc)
                if res == 7:
                    print(calc+"=7")
                    return
                calc = k_calc
            calc = j_calc
        calc = i_calc


if __name__ == '__main__':
    c()

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("{}+{}+{}+{}=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:
S = input()
val_l = [int(S[0]),int(S[1]),int(S[2]),int(S[3])]
l = len(S)

def main():
  for i in range(1<<l-1):
    ans = 0
    opp=""
    ans_l =[0,0,0,0]
    for j in range(l):
      if j==l-1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      elif (i>>j)&1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      else:
        ans -= val_l[l-j-1]
        opp = "-"+opp
      ans_l[l-j-1] = S[l-j-1]
    if ans == 7:
      print(S[0]+opp[1]+S[1]+opp[2]+S[2]+opp[3]+S[3]+"=7")
      return
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
S = input()
s = []
for i in range(4):
    s.append(int(S[i]))
op0 = '+'
op1 = '-'
if s[0] + s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op0, s[3]))
elif s[0] + s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op1, s[3]))
elif s[0] + s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op0, s[3]))
elif s[0] + s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op1, s[3]))
elif s[0] - s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op0, s[3]))
elif s[0] - s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op1, s[3]))
elif s[0] - s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op0, s[3]))
elif s[0] - s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op1, s[3]))

Submission status: Accepted

Solution code:
S=input()
ls=list(map(int,[S[i] for i in range(4)]))
for bit in range(1<<3):
  su=ls[0]
  st=str(ls[0])
  for i in range(3):
    if bit&(1<<i):
      su+=ls[i+1]
      st=st+"+"+str(ls[i+1])
    else:
      su-=ls[i+1]
      st=st+"-"+str(ls[i+1])
  if su==7:
    st=st+"=7"
    print(st)
    exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=input()
S=list(map(int,S))

def calc(index,num):
    if index&1==1:
        return [num,"+"]
    else:
        return [-num,"-"]

for i in range(8):
    ans=S[0]
    s1=calc(i,S[1])[1]
    ans+=calc(i,S[1])[0]
    s2=calc(i>>1,S[2])[1]
    ans+=calc(i>>1,S[2])[0]
    s3=calc(i>>2,S[3])[1]
    ans+=calc(i>>2,S[3])[0]
    if ans==7:
        print(str(S[0])+s1+str(S[1])+s2+str(S[2])+s3+str(S[3])+"=7")
        exit()

Submission status: Accepted

Solution code:
a,b,c,d=input()
e=['+','-']
for i in e:
    for j in e:
        for k in e:
            ans=a+i+b+j+c+k+d
            if eval(ans)==7:
                print(ans+'=7')
                exit()

Submission status: Accepted

Solution code:
import sys
X = int(input())
D = X%10
X = (X - D)//10
C = X%10
X = (X - C)//10
B = X%10
A = (X - B)//10
sm = A+B+C+D
if sm == 7:
    print("%d+%d+%d+%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*D == 7:
    print("%d+%d+%d-%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*C == 7:
    print("%d+%d-%d+%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*B == 7:
    print("%d-%d+%d+%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*(B+C) == 7:
    print("%d-%d-%d+%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*(B+D) == 7:
    print("%d-%d+%d-%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*(C+D) == 7:
    print("%d+%d-%d-%d=7"%(A,B,C,D))
    sys.exit()
elif sm-2*(B+C+D) == 7:
    print("%d-%d-%d-%d=7"%(A,B,C,D))
    sys.exit()

Submission status: Accepted

Solution code:
S = list(input())
ans = [""]*9
for bit in range(1<<3):
  a = int(S[0])
  ans = [None]*9
  ans[0]=S[0]
  ans[2]=S[1]
  ans[4]=S[2]
  ans[6]=S[3]
  ans[8]="7"
  ans[7]="="
  for k in range(3):
    if bit&(1<<k):
      a+=int(S[k+1])
      if k==0:
      	ans[1]="+"
      elif k==1:
        ans[3]="+"
      else:
        ans[5]="+"
    else:
      a-=int(S[k+1])
      if k==0:
      	ans[1]="-"
      elif k==1:
        ans[3]="-"
      else:
        ans[5]="-"
  if a==7:
    print("".join(ans))
    exit()

Submission status: Accepted

Solution code:
A, B, C, D = input()
o = ["+", "-"]
for i in range(2):
  for j in range(2):
    for k in range(2):
      s = A + o[i] + B + o[j] + C + o [k] + D
      if eval(s) == 7:
        print(s + "=7")
        exit()

Submission status: Accepted

Solution code:
a=input()
def dfs(i,s,l):
    if i==3:
        if s==7:
            print(l+'=7')
            exit()
    else:
        dfs(i+1,s+int(a[i+1]),l+'+'+a[i+1])
        dfs(i+1,s-int(a[i+1]),l+'-'+a[i+1])

dfs(dfs(0,int(a[0]),a[0]))

Submission status: Accepted

Solution code:
a,b,c,d = map(str, input())
op_list = ['+', '-']


for op1 in op_list:
    for op2 in op_list:
        for op3 in op_list:
            f = a+op1+b+op2+c+op3+d
            if eval(f) == 7:
                print(f+'=7')
                exit()

Submission status: Accepted

Solution code:
S = input().strip()
op = ["+","-"]
ind = 0
for op1 in op:
    for op2 in op:
        for op3 in op:
            if eval(S[0]+op1+S[1]+op2+S[2]+op3+S[3])==7:
                print(S[0]+op1+S[1]+op2+S[2]+op3+S[3]+"=7")
                ind = 1
                break
        if ind==1:break
    if ind==1:break

Submission status: Accepted

Solution code:
S = input()
a,b,c,d = S[0],S[1],S[2],S[3]
op_list = ['+','-']
for op1 in op_list:
    for op2 in op_list:
        for op3 in op_list:
            f = a+op1+b+op2+c+op3+d
            if eval(f)==7:
                print(f+'=7')
                exit()

Submission status: Accepted

Solution code:
A,B,C,D = map(int, list(input()))
ans = ''
op_list = ['+', '-']
for op1 in op_list:
    for op2 in op_list:
        for op3 in op_list:
            formula = "{}{}{}{}{}{}{}".format(A,op1,B,op2,C,op3,D)
            if 7 == eval(formula):
                ans = formula+"=7" 
                break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ops = ["+","-"]

for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            x = eval(a+op1+b+op2+c+op3+d)
            if x == 7:
                print(a+op1+b+op2+c+op3+d+"=7")
                exit()

Submission status: Accepted

Solution code:
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    a = list(map(int, list(str(input().rstrip('\n')))))
    ls = ["+", "-"]
    for v in itertools.product(ls, repeat=3):
        t = a[0]
        s = [str(a[0])]
        for i in range(len(v)):
            if v[i] == "+":
                t += a[i + 1]
                s.append("+")
            else:
                t -= a[i + 1]
                s.append("-")
            s.append(str(a[i + 1]))
        if t == 7:
            s.append("=7")
            print("".join(s))
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1 #隙間の数

for i in range(2**3):
    tmp = s[0]
    for j in range(n):
        if (i >> j) & 1:
            tmp += "+"

        else:
            tmp += "-"

        tmp += s[j+1]

    list_tmp = [tmp[0], tmp[1:3], tmp[3:5], tmp[5:7]]

    res = 0
    for j in list_tmp:
        res += int(j)

    if res == 7:

        print(tmp + "=7")
        exit()

Submission status: Accepted

Solution code:
import sys
df = list(map(int, list(str(input()))))
counter = 0
for i in range(2**3):
    bin_i = format(i, '03b')
    counter += df[0]
    for j in range(3):
        if bin_i[j] == '1':
            counter -= df[j+1]
        else:
            counter += df[j+1]
    if counter == 7:
        result = str(df[0])
        for j in range(3):
            if bin_i[j] =='0':
                result += '+' + str(df[j+1])
            else:
                result += '-' + str(df[j+1])
        result += '=7'
        print(result)
        sys.exit()
    else:
        counter = 0

Submission status: Accepted

Solution code:
def f(i,s,t):
    if i==3:
        if t==7:
            print(s + '=7')
            exit()
    
    else:
        f(i+1,s+'-'+a[i+1],t-int(a[i+1]))
        f(i+1,s+'+'+a[i+1],t+int(a[i+1]))

a=input()
f(0,a[0],int(a[0]))

Submission status: Accepted

Solution code:
value = input()
n = len(value) - 1

for i in range(n ** 2):
    sign = ["+"] * n
    for j in range(n):
        if(i >> j & 1):
            sign[n-1-j] = "-"
    formula = ""
    for x,y in zip(value,sign+[""]):
        formula += x + y 
    if eval(formula) == 7:
        print(formula + "=7")
        break

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    # l = list(map(int, input().split()))
    ll=input().strip()
    l=[0 for i in range(4)]
    for i in range(len(l)):
        l[i]=int(ll[i])
    NUM_CASE=3

    for case in range(2**NUM_CASE):
        # eprint("case : " + str(case))
        sum=l[0]
        
        stack=[]
        S=""
        for index in range(NUM_CASE):
            if (case>>index) & 1 == 1:
                # eprint("l[%d] : %d" % (index+1,l[index+1]) )
                sum+=l[index+1]
                stack.append("+")
            else:
                # eprint("l[%d] : %d" % (index+1,l[index+1]) )
                sum-=l[index+1]
                stack.append("-")
        # eprint("sum : " + str(sum))
        if sum==7:
            for i in range(4):
                S+=str(l[i])
                if i!=3:
                    S+=str(stack[i])
            S+="=7"
            print(S)
            return
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(next_idx, exp):
  if next_idx >= len(S):
    total = eval("".join(exp))
    return exp if total == 7 else ""

  return max(solve(next_idx+1, exp+"+"+S[next_idx]), solve(next_idx+1, exp+"-"+S[next_idx]))

S = input()
print(solve(1, S[0]) + "=7")

Submission status: Accepted

Solution code:
# C 
li = list(input())
li = [int(num) for num in li]

def dfs(index, total, ans):
    if (index==3):
        if total + li[index] == 7:
            return ans + '+' + str(li[index])
        elif total - li[index] == 7:
            return ans + '-' + str(li[index])
        else:
            return None
   
    if index == 0:
        return dfs(index + 1, total+li[index], ans+str(li[index]))
    else:
        val1 = dfs(index + 1, total + li[index], ans + '+' + str(li[index]))
        val2 = dfs(index + 1, total - li[index], ans + '-' + str(li[index]))
        if val1:
             return val1
        if val2:
             return val2
print(dfs(0, 0, '') + '=7')

Submission status: Accepted

Solution code:
ABCD = input()

ops = ['+', '-']

for i in range(2**3):

    ans = int(ABCD[0])
    op = []
    for j in range(3):
        if ops[i % 2] == '+':
            ans += int(ABCD[j+1])
        else:
            ans -= int(ABCD[j+1])
        op.append(ops[i%2])
        i //= 2

    if ans == 7:
        print(ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3] + '=7')
        break

Submission status: Accepted

Solution code:
s=input()
for bit in range(1<<3):
    l=s[0]
    for i in range(3):
        if bit & (1<<i):
            l+='+'+s[i+1]
        else:
            l+='-'+s[i+1]
    if eval(l)==7:
        print(l+'=7')
        exit()

Submission status: Accepted

Solution code:
def main():
    li = [int(i) for i in input()]
    t = li[1:]
    op = ["+", "+", "+"]
    t_sum = sum(li)
    if t_sum == 7:
        print("{}+{}+{}+{}=7".format(li[0], li[1], li[2], li[3]))
    else:
        for i in range(3):
            if t_sum - 2*t[i] == 7:
                op[i] = "-"
                print("{}{}{}{}{}{}{}=7".format(li[0], op[0], li[1], op[1], li[2], op[2], li[3]))
                return
            elif t_sum - 2*t[i] > 7:
                for j in range(1, 3):
                    if t_sum - (t[i] + t[i-j])*2 == 7:
                        op[i] = "-"
                        op[i-j] = "-"
                        print("{}{}{}{}{}{}{}=7".format(li[0], op[0], li[1], op[1], li[2], op[2], li[3]))
                        return

main()

Submission status: Accepted

Solution code:
import sys

a, b, c, d = tuple(input())
op = ('+', '-')

for op1 in op:
    for op2 in op:
        for op3 in op:
            res = a + op1 + b + op2 + c + op3 + d
            if eval(res) == 7:
                print(res + '=7')
                sys.exit(0)

Submission status: Accepted

Solution code:
a, b, c, d = map(int, list(input()))
abcd = [a, b, c, d]
anss = []
import copy
def dfs(add_list, index):
    value = abcd[0]
    if index == 2:
        for add_index in range(len(add_list)):
            if add_list[add_index]:
                value += abcd[add_index+1]
            else:
                value -= abcd[add_index+1]

        if value == 7:
            anss.append(add_list)

    else:
        new_index = index + 1
        new_add_list = copy.copy(add_list)
        new_add_list[new_index] = False
        dfs(new_add_list, new_index)

        new_add_list = copy.copy(add_list)
        new_add_list[new_index] = True
        dfs(new_add_list, new_index)


def main():
    dfs([True,True,True], 0)
    dfs([False,True,True], 0)

    ans = anss[0]
    ans_str = []
    for op in ans:
        if op:
            ans_str.append("+")
        else:
            ans_str.append("-")
    ret_str = ""
    for index in range(len(ans_str)):
        ret_str += str(abcd[index])
        ret_str += ans_str[index]
    ret_str += str(abcd[-1])
    ret_str += "=7"
    print(ret_str)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A = input()
for i in range(2**3):
    s = A
    for j in range(3):
        if i>>j & 1:
            s = s[:j-3]+"+"+s[j-3:]
        else:
            s = s[:j-3]+"-"+s[j-3:]
    ans = int(s[0])
    for k in range(len(s)):
        if k%2 == 0:
            n = int(s[k])
        if s[k-1] == "+":
            ans += n
        elif s[k-1] == "-":
            ans -= n
    if ans == 7:
        print(s+"=7")
        break

Submission status: Accepted

Solution code:
# coding: utf-8
ABCD = input() # ABCDの入力
op = ["*", "*", "*"] #解答出力のため演算子用の変数listを用意
def operate(ans, i): #再帰関数で解く
    if i == 3:
        if ans == 7:
            print("{}{}{}{}{}{}{}=7".format(ABCD[0], op[0], ABCD[1], op[1], ABCD[2], op[2], ABCD[3]))
            exit()
    else:
        op[i] = op[i].replace("*", "+").replace("-", "+") # 演算子の書き換え
        operate(ans + int(ABCD[i + 1]), i + 1)
        op[i] = op[i].replace("+", "-") # 演算子の書き換え
        operate(ans - int(ABCD[i + 1]), i + 1)
operate(int(ABCD[0]), 0)

Submission status: Accepted

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

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:
s = input()
sLen = len(s)
for i in range(2**(sLen-1)):
  tmpAns = 0
  tmpOp =''
  for j in range(sLen-1):
    if((i>>j)&1):
      tmpAns += int(s[sLen-1-j])
      tmpOp += '+'
    else:
      tmpAns -= int(s[sLen-1-j])
      tmpOp += "-"
  if tmpAns+int(s[0]) == 7:
    print(s[0]+tmpOp[2]+s[1]+tmpOp[1]+s[2]+tmpOp[0]+s[3]+"=7")
    break

Submission status: Accepted

Solution code:
N = input()
n = [v for v in N]

l = len(n)
C = []

for i in range(2**(l-1)):
    c = ''
    for j in range(l):
        c += n[j]
        if i >> j & 1:
            c += '+'
        else:
            c += '-'
    if eval(c[:-1]) == 7:
        print('{}=7'.format(c[:-1]))
        exit()

Submission status: Accepted

Solution code:
# C - Train Ticket
S = input()
op_cnt = len(S) - 1

for i in range(2 ** op_cnt):
    op = ['-'] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt-1-j] = '+'
    formula = ''
    for a, b in zip(S, op + ['']):
        formula += a + b
    if eval(formula) == 7:
        print(formula + '=7')
        break

Submission status: Accepted

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

o=['+++','++-','+-+','+--','-++','-+-','--+','---']

ans=-1
for i in range(8):
    if eval(a+o[i][0]+b+o[i][1]+c+o[i][2]+d)==7:
        ans=i
        break

print(a+o[i][0]+b+o[i][1]+c+o[i][2]+d+'=7')

Submission status: Accepted

Solution code:
S= list(input())
Answer = "a"

for i in ['+','-']:
  for j in ['+','-']:
    for k in ['+','-']:
      if eval(S[0]+i+S[1]+j+S[2]+k+S[3])==7:
        Answer = S[0]+i+S[1]+j+S[2]+k+S[3]+'=7'
        break

print(Answer)

Submission status: Accepted

Solution code:
import sys
abcd = input()
a, b, c, d = map(int, abcd)
op = [1, -1]
s_op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+b*op[i]+c*op[j]+d*op[k] == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    a, s_op[i], b, s_op[j], c, s_op[k], d
                    ))
                sys.exit(0)

Submission status: Accepted

Solution code:
s = input()
for i in range(2**(len(s)-1)):
    ans = s[0]
    for j in range(len(s)-1):
        if i >> j & 1:
            ans += "+"
        else: ans += "-"
        ans += s[j+1]
    if eval(ans) == 7:print(ans+"=7");exit()

Submission status: Accepted

Solution code:
a,b,c,d = input()
abcd = list(map(int,[a,b,c,d]))
op = [None]*3
for i in range(2**3):
    f = abcd[0]
    for j in range(3):
        if ((i >> j) & 1):
            f += abcd[j+1]
            op[j] = '+'
        else:
            f -= abcd[j+1]
            op[j] = '-'
    if f == 7:
        print(a+op[0]+b+op[1]+c+op[2]+d+'=7')
        exit()

Submission status: Accepted

Solution code:
def f(i,s):
    if i == len(n)-1:
        if eval(s) == 7:
            ans.append(s)
            return 1
        else:return 0
    return f(i+1,s+"-"+n[i+1])+f(i+1,s+"+"+n[i+1])
n = input()
ans = []
f(0,n[0])
print(ans[0]+"=7")

Submission status: Accepted

Solution code:
from math import sqrt


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    s = input()
    n = len(s) - 1
    for k in range(2 ** n):
        ops = list(("{0:{fill}%db}" % n).format(k, fill="0").replace("0", "+").replace("1", "-"))
        ops.append("")
        q = ""
        for a, b in zip(s, ops):
            q += a + b
        v = eval(q)
        if v == 7:
            print(q + "=7")
            break


main()

Submission status: Accepted

Solution code:
import sys

s = input()

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

ans = a
for i in range(2):
	if i == 0:
		ans += b
		s1 = '+'
	else:
		ans -= b
		s1 = '-'
	for j in range(2):
		if j == 0:
			ans += c
			s2 = '+'
		else:
			ans -= c
			s2 = '-'
		for k in range(2):
			if k == 0:
				ans += d
				s3 = '+'
			else:
				ans -= d
				s3 = '-'
			if ans == 7:
				print(s[0]+s1+s[1]+s2+s[2]+s3+s[3]+"=7")
				sys.exit()
			else:
				if k == 0:
					ans -= d
				else:
					ans += d
		if j == 0:
			ans -= c
		else:
			ans += c
	if i == 0:
		ans -= b
	else:
		ans += b

Submission status: Accepted

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

import sys
for bit in range(2 ** 3):
    sum = ls[0]
    ans = str(ls[0])
    for i in range(3):
        if bit >> i & 1:
            sum += ls[i + 1]
            ans += "+" + str(ls[i + 1])
        else:
            sum -= ls[i + 1]
            ans += "-" + str(ls[i + 1])
    if sum == 7:
        print(ans + "=7")
        sys.exit()

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1  # スキマの数
for i in range(2**n):  # +, -の組み合わせ数
    p_or_m = ["-"] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            p_or_m[n - 1 - j] = "+"

    formula = ""
    for k in range(n):
        formula += s[k] + p_or_m[k]
    formula += s[3]
    if eval(formula) == 7:
        print(formula+"=7")
        break

Submission status: Accepted

Solution code:
s = input()
S = [0]*len(s)
for i in range(len(s)):
    S[i] = int(s[i])

# 0:-, 1:+
op = [0]*(len(S) - 1)
for i in range(2**len(op)):
    op = [0]*(len(S) - 1)
    for j in range(len(op)):
        if (i >> j & 1):
            op[j] = 1
    tmp = S[0]
    for j in range(len(op)):
        if op[j] == 0:
            tmp -= S[j+1]
        else:
            tmp += S[j+1]
    if tmp == 7:
        ans = op[:]
ans_str = s[0]
for i in range(len(S)-1):
    if ans[i] == 0:
        ans_str = ans_str + "-"
    else:
        ans_str = ans_str + "+"
    ans_str = ans_str + s[i+1]
ans_str = ans_str + "=7"
print(ans_str)

Submission status: Accepted

Solution code:
f=input()
o=['+','-']
for i in o:
    for j in o:
        for k in o:
            s=f[0]+i+f[1]+j+f[2]+k+f[3]+"==7"
            if eval(s):
                print(s.replace('==','='))
                exit()