資料產生python指令碼

來源:互聯網
上載者:User

標籤:pre   pos   rand   data   python   ++   asi   sys   random   

下面是項目結構:

--data 存放資料的檔案夾--main.cpp 題目的正確資料--prodData.py  產生輸入輸出資料指令碼--test.cpp    測試代碼--testData.py  測試代碼是否正確指令碼

 

prodData.py

#-*- coding:utf-8 -*-‘‘‘@auther: Starry@file: prodData.py@time: 2018/1/17 15:47‘‘‘import randomimport osDATASIZE = 10‘‘‘每個資料一組資料‘‘‘for i in range(DATASIZE):    print(‘The %dth set of test data is being produced.‘ % i)    with open(‘./data/test‘+str(i)+‘.in‘,‘w‘,encoding=‘utf-8‘) as f:        N = random.randint(1, 100000)        M = random.randint(1, 100000)        f.write(str(N)+‘ ‘+str(M)+‘\n‘)        for j in range(M):            a = random.randint(1,10000)            b = random.randint(1,10000)            c = random.randint(1,200)            f.write(str(a)+‘ ‘+str(b)+‘ ‘+str(c)+‘\n‘)    with open(‘./data/test‘+str(i)+‘.out‘,‘w‘,encoding=‘utf-8‘) as f:        pass    os.system(‘g++ -std=c++11 main.cpp -o main‘)    os.system(‘main < data\\test‘+str(i)+‘.in >> data\\test‘+str(i)+‘.out‘)‘‘‘多組資料 0 結束‘‘‘# for i in range(DATASIZE):#     print(‘The %dth set of test data is being produced.‘%i)#     with open(‘./data/test‘+str(i)+‘.in‘,‘w‘,encoding=‘utf-8‘) as f:#         while True:#             N = random.randint(-70,1000)#             if N <= 0:#                 f.write(str(0)+‘\n‘)#                 break#             f.write(str(N)+‘\n‘)#             for j in range(N):#                 a = random.randint(1,50)#                 f.write(str(a)+‘ ‘)#             f.write(‘\n‘)#             M = random.randint(0,1000)#             f.write(str(M)+‘\n‘)#     with open(‘./data/test‘+str(i)+‘.out‘,‘w‘,encoding=‘utf-8‘) as f:#         pass#     os.system(‘g++ -std=c++11 main.cpp -o main‘)#     os.system(‘main < data\\test‘+str(i)+‘.in >> data\\test‘+str(i)+‘.out‘)‘‘‘多組資料‘‘‘# for i in range(DATASIZE):#     print(‘The %dth set of test data is being produced.‘ % i)#     with open(‘./data/test‘+str(i)+‘.in‘,‘w‘,encoding=‘utf-8‘) as f:#         for j in range(random.randint(1,20)):#             N = random.randint(1, 100)#             M = random.randint(1, 100)#             K = random.randint(1, 100)#             S = random.randint(1, 100)#             f.write(str(N)+‘ ‘+str(M)+‘ ‘+str(K)+‘ ‘+str(S)+‘\n‘)#             for k in range(K):#                 a = random.randint(1,20)#                 b = random.randint(1,20)#                 f.write(str(a)+‘ ‘+str(b)+‘\n‘)#     with open(‘./data/test‘+str(i)+‘.out‘,‘w‘,encoding=‘utf-8‘) as f:#         pass#     os.system(‘g++ -std=c++11 main.cpp -o main‘)#     os.system(‘main < data\\test‘+str(i)+‘.in >> data\\test‘+str(i)+‘.out‘)

 

 

testData.py

#-*- coding:utf-8 -*-‘‘‘@auther: Starry@file: testData.py@time: 2018/1/17 15:46‘‘‘import osDATASIZE = 10os.system(‘g++ test.cpp -o test‘)WA = Falsefor i in range(DATASIZE):    print(‘The %dth set of data is being tested.‘%i)    os.system(‘test < data\\test‘+str(i)+‘.in > te.out‘)    flag = os.system(‘fc data\\test‘+str(i)+‘.out te.out > nul‘)    if flag != 0:        print(‘Wrong answer on test‘+str(i)+‘.in!!!‘)        WA = Trueif not WA:    print("Accepted!!!")

 

資料產生python指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.