program_file_path = "main.cpp"
result_file_path = "result.txt"
with open(program_file_path,mode="r") as f:
lines = f.readlines()
kadai_list = []
data_list = []
kadai = None
loop = None
size = None
kadai_flag = " //課題"
for i,line in enumerate(lines):
try:
line = line.replace("\n","")
if(len(line) > len(kadai_flag) and kadai_flag == line[:len(kadai_flag)]):
_kadai = line[len(kadai_flag):]
try:
float(_kadai)
except:
continue
if(kadai is not None):
kadai_list.append(kadai)
data_list.append(
(loop,size)
)
kadai = _kadai
elif("const int default_loop" in line):
_loop = line.split("=")[-1].replace(";","")
try:
float(_loop)
except:
continue
loop = _loop
elif("const int default_size" in line):
_size = line.split("=")[-1].replace(";","")
try:
float(_size)
except:
continue
size = _size
except Exception as e:
print(f"raised exception at line{i} : {line}")
print()
print(e)
quit()
if(kadai is not None):
kadai_list.append(kadai)
data_list.append(
(loop,size)
)
with open(result_file_path,mode="w") as f:
for i in range(len(kadai_list)):
kadai = kadai_list[i]
loop,size = data_list[i]
f.write(f"\nexercise {kadai}: loop = {loop}, size = {size}\n")
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme