Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include<vector>
  5. #include <ctime>
  6. using namespace std;
  7.  
  8. //vector<vector<string>> CreateDynamicMatrix( int rows, int col)
  9. //{
  10. // vector<vector<string>> vec;
  11. // //Grow rows by m
  12. // vec.resize(rows );
  13. // for (int i = 0; i < rows; ++i)
  14. // {
  15. // //Grow Columns by n
  16. // vec[i].resize(col);
  17. // }
  18. // return vec;
  19. //}
  20.  
  21. //vector<int> DestinationFunction(int size)
  22. //{
  23. // srand(time(NULL));
  24. // vector<int> vec;
  25. // vec.resize(size);
  26. // for(int i=0;i<size;i++)
  27. // {
  28. // vec[i] = rand() % size + 1;
  29. // }
  30. //}
  31.  
  32. //vector<vector<string>> ReadDataFromFile(string fileName)
  33. //{
  34. // ifstream file(fileName);
  35. // string line;
  36. // if (file.is_open())
  37. // {
  38. // getline(file, line);
  39. // cout << line << '\n';
  40. //
  41. // getline(file, line);
  42. // cout << line << '\n';
  43. //
  44. // //int sizeOfArray = stoi(line);
  45. // int sizeOfArray = 17;
  46. // vector<vector<string>>matrix = CreateDynamicMatrix(sizeOfArray, sizeOfArray);
  47. //
  48. //
  49. // string lineTest;
  50. // while (getline(file, lineTest))
  51. // {
  52. // for (int i = 0; i < sizeOfArray; i++)
  53. // {
  54. // for (int j = 0; j < sizeOfArray; j++)
  55. // {
  56. // file >> matrix[i][j];
  57. // }
  58. // }
  59. // }
  60. //
  61. // file.close();
  62. // return matrix;
  63. // }
  64. //
  65. // else cout << "Unable to open file";
  66. //
  67. //}
  68.  
  69. int main(int argc, char* argv[])
  70. {
  71.  
  72. //string matrixFile = argv[1];
  73. string matrixFile = "data17.txt";
  74. vector<vector<string>> matrix;
  75. string matrixx[17][17];
  76. matrix.resize(17);
  77. for (int i = 0; i < 17; ++i)
  78. {
  79. //Grow Columns by n
  80. matrix[i].resize(17);
  81. }
  82. int size = 0;
  83. //matrix = ReadDataFromFile(matrixFile);
  84.  
  85. ifstream x(matrixFile);
  86.  
  87. if (x.is_open())
  88. {
  89. string line;
  90. string s;
  91. getline(x, s);
  92. cout << s << '\n';
  93.  
  94. getline(x, s);
  95. cout << s << '\n';
  96.  
  97. int sizeOfArray = stoi(s);
  98. //int sizeOfArray = 17;
  99.  
  100. //ifstream x("data17.txt");
  101.  
  102.  
  103.  
  104.  
  105. while(getline(x, s))
  106. {
  107. for (int i = 0; i < 17; i++)
  108. {
  109. for (int j = 0; j < 17; j++)
  110. {
  111. x >> matrixx[i][j];
  112. }
  113. }
  114. }
  115. x.close();
  116.  
  117. }
  118.  
  119. //string lineTest;
  120. /*while (getline(file, line))
  121. {
  122. for (int i = 0; i < sizeOfArray; i++)
  123. {
  124. for (int j = 0; j < sizeOfArray; j++)
  125. {
  126. file >> matrix[i][j];
  127. }
  128. }
  129. }*/
  130.  
  131.  
  132.  
  133. else cout << "Unable to open file";
  134.  
  135.  
  136.  
  137.  
  138. cout << "Tablica\n";
  139. for (int i = 0; i < 17; i++)
  140. {
  141. for (int j = 0; j < 17; j++)
  142. {
  143. cout << matrixx[i][j] << " ";
  144. }
  145. cout << "\n";
  146. }
  147.  
  148. int destinationFunc[5] = { 1,13,2,5,6 };
  149.  
  150. int result = 0;
  151. int value = 0;
  152.  
  153. for (int i = 0; i < 4; i++)
  154. {
  155. value = stoi(matrix[destinationFunc[i]-1][destinationFunc[i+1]-1]);
  156. result += value;
  157. }
  158. value = stoi(matrix[destinationFunc[4]-1][destinationFunc[0]-1]);
  159. result += value;
  160.  
  161. cout << "Kundel bury,\nKundel bury,\nwypierdala wszystkim buly\nWynik: " << result;
  162.  
  163.  
  164.  
  165.  
  166. cin.get();
  167. return 0;
  168.  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement