对拍

c++#

duipai.cpp

#include <bits/stdc++.h>  
using namespace std;  
  
int main(){  
    for(int i=0;i<100000;i++){  
       system("mk");  // ./mk
       system("baoli < in.txt > baoli.out");  
       system("std < in.txt > std.out");  
       if(system("fc baoli.out std.out")){  //linux/mac diff
          printf("%d !!!!!!!!",i);  
          while(1);  
       }  
    }  
    return 0;  
}

mk.cpp

#include <cstdio>  
#include <cstdlib>  
#include <algorithm>  
  
using namespace std;  
  
int main(){  
    int seed;  
    freopen("seed.txt", "r", stdin);  
    scanf("%d",&seed);  
  
    srand(seed+time(0));  
    for(int i=0;i<5;i++) rand();  
  
    freopen("seed.txt","w",stdout);  
    printf("%d\n", rand());  
  
    freopen("in.txt","w",stdout);  
    printf("%d %d\n",rand()%100,rand()%100);  
  
    return 0;  
}

mk_graph.cpp

#include <cstdio>  
#include <ctime>  
#include <algorithm>  
  
using namespace std;  
int vis[1000][1000];  
const int N=1e6+10;  
int main(){  
    int seed;  
    freopen("seed.txt", "r", stdin);  
    scanf("%d",&seed);  
  
    srand(seed+time(0));  
    for(int i=0;i<5;i++) rand();  
  
    freopen("seed.txt","w",stdout);  
    printf("%d\n", rand());  
  
    freopen("in.txt","w",stdout);  
    int t=rand()%10;  
    while(t--){  
        int n=rand()%N;  
        int m=rand()%(5*N);  
        printf("%d %d\n",n,m);  
        for(int i=1;i<=n;i++)  
            printf("%d ",rand()%10000);  
        for(int i=1;i<=m;i++){  
          int x=1,y=1;  
          while(x==y || vis[x][y]){  
             x = rand()%n+1;  
             y = rand()%n+1;  
          }  
          vis[x][y] = vis[y][x] = 1;// wuxiangtu  
          printf("%d %d\n",x,y);  
  
       }  
    }  
    return 0;  
}

python#

测试数据
luogu-dev/cyaron: CYaRon: Yet Another Random Olympic-iNformatics test data generator (github.com)

例子#

main.py

import os  
  
def run():  
    os.system('python mk.py')  
    os.system('python my.py < in.txt > my.txt')  
    os.system('python std.py < in.txt > std.txt')  
  
  
def check():  
    my = open('my.txt', 'r')  
    std = open('std.txt', 'r')  
    log = open('log.txt', 'w')  
    log.write('-----------All Error-----------\n')  
    # 这个i能记录顺序  
    for i, (a, b) in enumerate(zip(my, std)):  
        if a != b:  
            log.write('line:' + str(i + 1) + '\n')  
            log.write('-----my:' + a)  
            log.write('-----std:' + b)  
  
  
if __name__ == '__main__':  
    run()  
    check()

mk.py

import random  
import string  
out = open('in.txt', 'w')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.close()

my.py

a = int(input())  
b = int(input())  
for x in range(0, a):  
    b += 1  
print(b)

std.py

a = int(input())  
b = int(input())  
print(a+b)

构造随机数#

from random import *  
import string  
  
print('随机生成一个整数', randint(-10000000, 10000000))  
# 返回指定递增基数集合中的一个随机数 randrange ([start=1,] stop [,step=1])print('随机生成一个偶数', randrange(0, 10000000, 2))  
  
print('随机浮点数', uniform(0, 100))  
# 在指定字符中生成一个随机字符  
# choice(seq)从非空序列 seq 中随机选择一个元素  
print('随机字符', choice(string.ascii_letters))  
"""  
String模块中的常量:  
string.digits:数字0~9  
string.ascii_letters:所有字母(大小写)  
string.lowercase:所有小写字母  
string.printable:可打印字符的字符串  
string.punctuation:所有标点  
string.uppercase:所有大写字母  
"""  
# 在指定字符中生成指定数量的随机字符  
print(sample(string.ascii_letters + string.digits, 5))  
  
# str.join(seq) 将序列中的元素以str间隔连接生成一个新的字符串  
ran_str = ''.join(sample(string.ascii_letters + string.digits, 5))  
print('随机字符串', ran_str)  
ran_str2 = ','.join(sample(string.ascii_letters + string.digits, 5))  
print('随机字符串', ran_str2)

mk.py

import random  
import string  
out = open('in.txt', 'w')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.write(str(random.randint(-1000,1000))+'\n')  
out.close()

打乱数组的顺序#

items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]  
shuffle(items)  
for i in range(0, len(items)):  
    print(items[i], " ", end='')

计算时间#

单位为秒

import time  
time_start = time.time()  
# 程序  
time_end = time.time()  
print(time_end-time_start)

作者:AuroraKelsey

出处:https://www.cnblogs.com/AuroraKelsey/p/18545513

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   AuroraKelsey  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示