fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. void fitnessChart(vector<vector<vector<int> > > array, int&, int&);
  11.  
  12. int main(int argc, char* argv[])
  13. {
  14. int vertices;
  15. const int initial_value = 0;
  16. int pop;
  17. std::cout << "Enter the number of vertices:" << std::endl;
  18. std::cin >> vertices;
  19. std::cout << "Enter the size of the population:" << std::endl;
  20. std::cin >> pop;
  21.  
  22. std::vector<int> sub_sub_array(vertices, initial_value);
  23. std::vector<std::vector<int> > sub_array(vertices, sub_sub_array);
  24. std::vector<std::vector<std::vector<int> > > array(pop, sub_array);
  25.  
  26. int e;
  27. for(int i = 0; i < pop; ++i)
  28. {
  29. for(int j = 0; j < vertices; ++j)
  30. {
  31. for(int k = 0; k < vertices; ++k)
  32. {
  33. e = rand() %2;
  34. if (j == k)
  35. {
  36. array[i][j][k] = 9;
  37. break;
  38. }
  39. else
  40. {
  41. array[i][j][k] = e;
  42. array[i][k][j] = e;
  43. }
  44.  
  45. }
  46. }
  47. }
  48.  
  49.  
  50.  
  51. // Print out the full array contents
  52. for(int i = 0; i < pop; ++i)
  53. {
  54. for(int j = 0; j < vertices; ++j)
  55. {
  56. for(int k = 0; k < vertices; ++k)
  57. {
  58. if(j!=k)
  59. {
  60. std::cout << " " << array[i][j][k] << " ";
  61. }
  62. else
  63. std::cout << " - ";
  64. }
  65. std::cout << "\n";
  66. }
  67. std::cout << "\n";
  68. }
  69.  
  70. for(int i = 0; i < pop; i++)
  71. {
  72. fitnessChart(array, vertices, i);
  73. }
  74.  
  75. system ("pause");
  76. }
  77.  
  78. void fitnessChart(vector<vector<vector<int> > > array, int& vertices, int& i)
  79. {
  80. int count=0, match, first, j=0, k=1;
  81.  
  82. for(k; k < vertices; k++)
  83. {
  84. match = array[i][j][k];
  85. first = j;
  86. j = k;
  87.  
  88. for(k; k < vertices; k++)
  89. {
  90. if (array[i][j][k+1] == match)
  91. {
  92. if (array[i][k+1][first] == match)
  93. {
  94. count++;
  95. }
  96. }
  97. }
  98. }
  99. cout << count << endl;
  100. }
  101.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:21: error: windows.h: No such file or directory
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:75: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result
prog.cpp: In function ‘void fitnessChart(std::vector<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, std::allocator<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > > >, int&, int&)’:
prog.cpp:82: warning: statement has no effect
prog.cpp:88: warning: statement has no effect
stdout
Standard output is empty