Machine :) (Codechef Contest Problem)

 Question:-

Charlie found a machine while on exploration. He brought the machine to you but you realize that first you need to unlock the machine with a series of steps. Luckily, Charlie had also found a paper containing series of numbers to unlock the machine in  steps. Each step requires an input  to proceed. But unfortunately, the key of digit  is broken.

You also find out that instead of a single input, you can give two inputs for each step such that the result adds upto . Since the key  is broken, you proceed with the option of breaking up the number into two parts so that you can avoid entering the digit .

Your job is to write a program which will break into two parts  and  such that  and neither of  or  has digit .

Example: K = 3576 can be broken into a = 1633 and b = 1943

Input:

  • First line will contain , number of steps. Then the steps follow.
  • Each step contains of a single line of input, a integer 

Output:

For each testcase, output in a single line  and  separated by space. If there are multiple correct answers print any.

Constraints



It is guaranteed that each  will have at least one digit as .

Sample Input:

5
2745
47736
175
976
3777

Sample Output:

1186 1559
8420 39316
83 92
311 665
1584 2193

EXPLANATION:

For each step, output  and  sums upto  and don't contain digit  :






There could be multiple answers, all answers which result in  and where  and  don't contain a digit  will be accepted

Solution:-

for _ in range(int(input())):
          n = int(input())
          count = 0
          val = str(n)
          ans = ''
          for i in val:
                    if i == '7':
                              ans += '1'
                    else:
                              ans += i
          h = int(ans)
          original = n - h
          print(h, original)


Comments

Post a Comment

Popular posts from this blog

Chef And Work :) (Codechef August Cook-Off Contest Problem)

Bowling Strategy :) (Codechef Contest Problem)