10029. Corona2020

 

Ziya suspects that he has been infected with the coronavirus. Because of this, he is conducting research on his own DNA. As a result of his calculations, he found that three distinct numbers ab and c are connected to his DNA. Ziya believes that if, by substituting the operators + or - in place of the placeholders (<>) in the expression , it is possible to obtain the number 2020, then he is not infected with the coronavirus. Otherwise, if such a value cannot be obtained, it means he is infected.

Help Ziya determine whether he is infected with the coronavirus.

 

Input. Three integers a, b, and c (1 ≤ a, b, c ≤ 108) are given.

 

Output. If Ziya is not infected, print an expression of the form  that evaluates to 2020. Otherwise, print the word CORONA. There must be no spaces between the numbers and the operators in the expression.

 

Sample input 1

Sample output 1

2019 2020 2021

2019-2020+2021

 

 

Sample input 2

Sample output 2

2019 2020 2022

CORONA

 

 

SOLUTION

full search

 

Algorithm analysis

Check all possible operations between the numbers a, b, and c. If the value of the resulting expression equals 2020, print this expression. Otherwise, print the word CORONA.

 

Algorithm implementation

Read the input data.

 

scanf("%d %d %d", &a, &b, &c);

 

Iterate over all possible operations between the numbers. Depending on the result, print the appropriate answer.

 

if (a + b + c == 2020) printf("%d+%d+%d", a, b, c); else

if (a + b - c == 2020) printf("%d+%d-%d", a, b, c); else

if (a - b + c == 2020) printf("%d-%d+%d", a, b, c); else

if (a - b - c == 2020) printf("%d-%d-%d", a, b, c); else

                       printf("CORONA\n");

 

Python implementation

Read the input data.

 

a, b, c = map(int, input().split())

 

Iterate over all possible operations between the numbers. Depending on the result, print the appropriate answer.

 

if a + b + c == 2020:

  print(f"{a}+{b}+{c}")

elif a + b - c == 2020:

  print(f"{a}+{b}-{c}")

elif a - b + c == 2020:

  print(f"{a}-{b}+{c}")

elif a - b - c == 2020:

  print(f"{a}-{b}-{c}")

else:

  print("CORONA")