对n个数进行排序,随机构造10组输入数据,用到sprintf动态修改文件名,程序模板如下:
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
char s[105];
int main(){
srand(time(0));
for(k=1; k<=10; k++){
sprintf(s, "test%d.in", k);
freopen(s, "w", stdout);
n = rand()%20 + 5;
printf("%d\n", n);
for(i=1; i<=n; i++){
printf("%d ", rand()%100);
}
printf("\n");
}
return 0;
}