Hi everyone, I have a text file as below. Each row represent one set of solution. 10 row indicated 10 solution/ initial route. Each solution can be read like this.
Example solution row1:
0 8 9 5 4 11 10 2 12 7 3 6 1 0
Explanation: The route start from 0 then visit 8, then 9, 5, 4, ..., until return to 0.
Now, I need to store this data into array. I had try but error occurred. I don't know how to correct/adjust the errors. Hopefully you understand what i meant. Hoping help from anyone. Thanks.
Here is the input file:
0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 4 8 9 5 11 10 2 12 7 3 6 1 0
0 5 8 9 4 11 10 2 12 7 3 6 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 8 9 5 4 11 10 2 12 7 3 6 1 0
0 9 8 5 4 11 10 2 12 7 3 6 1 0
0 10 11 9 8 5 4 1 7 3 6 12 1 0
0 11 10 9 8 5 4 1 7 3 6 12 1 0
0 0 8 9 5 4 11 10 2 12 7 3 6 1 0
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 29 30 31 32 33 34 35 36 37
|
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int i, j;
int initialRoute = 10;
int main()
{
//open input file
ifstream inpInitialRoute("Route.txt");
//assign initial route to an array
for (i= 0; i<10; i++)
{
initialRoute[i] = 15;
for (j= 0; j<15; j++)
{
inpInitialRoute >> initialRoute[i][j];
//print array
cout >> initialRoute[i][j] >> endl;
}
}
//close input file
inpInitialRoute.close();
return 0;
}
|