online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
import numpy as np def main(): """ 你寫的東西 """ while True: try: row, col = map(int, input().split()) data1 = np.zeros([0, col]) for i in range(row): rowi = np.array(list(map(int, input().split()))) data1 = np.vstack((data1, rowi)) new = data1.T # 印出matrix for i in new: print(" ".join(str(int(j)) for j in i)) except: break if __name__ == "__main__": import unittest import random from unittest.mock import patch from io import StringIO class TestProblem(unittest.TestCase): def grouper(self, arr: list[int], col: int) -> list[list[int]]: """ 把一維陣列分割成二維的,每一列都包含指定數量的元素 """ iterators = [iter(arr)] * col return list(map(list, zip(*iterators))) def gen_test_cases(self, row: int, col: int) -> tuple[str, str]: """ 測資用這個函式生 """ chosen = random.sample(range(row * col), row * col) ipt = self.grouper(chosen, col) expected = list(map(list, zip(*ipt))) ipt.insert(0, [row, col]) def to_str(arr: list[list[int]]) -> str: return "\n".join(" ".join(map(str, line)) for line in arr) return to_str(ipt), to_str(expected) # unittest 主循環 @patch('builtins.input') @patch('sys.stdout', new_callable=StringIO) def test_random_cases(self, mock_stdout, mock_input): for _ in range(5): # 測試 5 個隨機案例,隨便改你喜歡的 row = random.randint(2, 10) col = random.randint(2, 10) with self.subTest(row=row, col=col): input_str, expected = self.gen_test_cases(row, col) mock_input.side_effect = input_str.split('\n') mock_stdout.truncate(0) mock_stdout.seek(0) main() actual = mock_stdout.getvalue().strip() self.assertEqual(actual, expected) unittest.main()

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue