Python代码 正常代码
1 2 for i in range (112 ): print (12 )
含有输入
1 2 a, b = map (int , input ().split()) print (a + b)
错误语法
执行时错误
超时测试
1 2 3 import timetime.sleep(6 ) print ('1108' )
超内存测试(128MB+)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import sysmegabyte = 1024 * 1024 memory_list = [] while True : try : memory_list.append(bytearray (megabyte)) print (f'已分配内存: {sys.getsizeof(memory_list) / megabyte} MB' ) except MemoryError: print ('内存分配失败!' ) break print (f'最终分配内存: {sys.getsizeof(memory_list) / megabyte} MB' )
输出过多
9776KB
1 2 for i in range (10000 ): print ("a" * 1000 )
28.6MB
1 2 for i in range (10000 ): print ("好" * 1000 )
潜在漏洞:
oj系统可能会真的在代码超时之前把代码执行完毕,然后最后才去检测 output.txt 文件的大小,这样有点危险。
python获取设备信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import osdef get_device_info (): current_dir = os.getcwd() print ("Current working directory:" , current_dir) partitions = os.statvfs(current_dir) total_space = partitions.f_frsize * partitions.f_blocks free_space = partitions.f_frsize * partitions.f_bfree used_space = total_space - free_space print ("Total space:" , total_space, "bytes" ) print ("Free space:" , free_space, "bytes" ) print ("Used space:" , used_space, "bytes" ) device_info = os.uname() print ("System:" , device_info.sysname) print ("Node name:" , device_info.nodename) print ("Release:" , device_info.release) print ("Version:" , device_info.version) print ("Machine:" , device_info.machine) if __name__ == "__main__" : get_device_info()
当前目录下的文件
1 2 3 import osa = os.listdir() print (a)
读取根目录下的所有文件夹
1 2 3 4 5 6 7 8 9 10 11 12 13 import osdef get_root_folders (): os.chdir("/" ) root_folders = [name for name in os.listdir("." ) if os.path.isdir(name)] return root_folders if __name__ == "__main__" : root_folders = get_root_folders() print ("Root folders:" , root_folders)
执行自定义指令
1 2 import osos.system("echo hi" )
在挂载卷中创建一个文件再删除
1 2 3 4 5 6 7 8 import osprint (os.listdir())with open ("aaa.txt" , "w" ) as f: f.write("test" ) print (os.listdir())os.remove("aaa.txt" ) print (os.listdir())
目前还需要做的:保护 input.txt, output.txt, error.txt 文件不被删除
C++ 正常代码
1 2 3 4 5 6 7 8 9 10 11 12 #include <iostream> using namespace std;int main () { int a; int b; cin >> a >> b; cout << a / b << endl; return 0 ; }
正常代码2
1 2 3 4 5 6 7 8 9 10 11 #include <iostream> using namespace std;int main () { for (int i = 0 ; i < 500 ; i++) { cout << i << endl; } return 0 ; }
严重超时
1 2 3 4 5 6 7 8 9 #include <iostream> using namespace std;int main () { while (true ) {} return 0 ; }
Author:
Littlefean
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan:
仅个人观点,buddy up!