0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AAAACCC

Last updated at Posted at 2024-12-12

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")

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?