D
D
Dauren S2020-09-17 20:48:35
Algorithms
Dauren S, 2020-09-17 20:48:35

Algorithm tester?

5f63a1e2ae04b060176682.png
I am writing this answer.

comp=[1,2,3],[4,5,6]
comp2=[1],[2]
def test(arr): 
  result=''
  for i in range(len(arr[0])):
    for j in range(len(arr)):
      result+=str(arr[j][i]) +' '
  print(result)

test(comp)

Writes wrong answer
Input file
3
1 2 3
4 5 6
Program output
1 4 2 5 3 6
Correct answer
1 4 2 5 3 6
Checker message
OK

Test 2
Input file
1
1
2
Program output
1 4 2 5 3 6
Correct answer
1 2
Checker message
Line 1 differs: out:
>1 4 2 5 3 6<
corr:
>1 2<

how to send 2 examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dauren S, 2020-09-21
@dauren101

with open('input.txt', 'r') as f:
    nums = f.read().splitlines()
    rows=nums[1:]
    common=[]
    result_string=''
    for r in rows:
        arr=r.split(' ')
        common.append(arr)
    for i in range(len(common[0])):
        for j in range(len(common)):
            result_string+=str(common[j][i])+' '
    print(result_string)

W
Wataru, 2020-09-17
@wataru

Um... You need to read data from an input file (in a task, this is input.txt or stdin).

import sys

n = int(sys.stdin.readline().strip())
comp = [sys.stdin.readline().strip().split(" "), sys.stdin.readline().strip().split(" ")]

This is not the fastest way to read in python, but it gets in the way when there are about 100000 numbers. You have only ~ 2000 numbers in the task and you can do that.
Note, here water numbers will be stored as strings. If you need to read numbers in the task, then you need to additionally apply int () to the elements with a map.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question