65,211
社区成员
发帖
与我相关
我的任务
分享#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include "time.h"
using namespace std;
const int N = 50;
int RangedRandDemo( int range_min, int range_max )
{
srand( (unsigned)time( NULL ) );
int u = (double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;
return u;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector< vector<double> > r(N);
char *names[] = {"RandOD1.txt", "RandOD2.txt", "RandOD3.txt", "RandOD4.txt", "RandOD5.txt",
"RandOD6.txt", "RandOD7.txt", "RandOD8.txt", "RandOD9.txt", "RandOD10.txt"};
ifstream infile_R;
ofstream outfile;
infile_R.open("bcOD.txt");
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
double num;
infile_R >> num;
r[i].push_back(num);
}
}
infile_R.close();
double temp[N][N] = {0};
for (int ix = 0; ix < 10; ++ix)
{
srand( (unsigned)time( NULL ) );
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < N; ++j)
{
temp[i][j] = r[i][j] + ( RangedRandDemo(1, 100) );
}
}
outfile.open(names[ix]);
for (size_t i = 0; i < N; ++i)
{
for (size_t j = 0; j < N; ++j)
{
outfile << temp[i][j] << " ";
}
outfile << endl;
}
outfile.close();
outfile.clear();
}
return 0;
}