Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define NMAX 100000
  5.  
  6. struct Video
  7. {
  8. int ok;
  9. int size;
  10. };
  11.  
  12. struct Endpoint {
  13. int DataCenterLatency;
  14. int NrCaches;
  15. int Caches[NMAX][2];
  16. int NrRequests;
  17. int Requests[NMAX][2];
  18. };
  19.  
  20. int main(int argc, char *argv[]) {
  21.  
  22. FILE* f;
  23. f = fopen(argv[1], "r");
  24. // if (f == NULL)
  25. // return 0;
  26.  
  27. int R,C,X;
  28. int V,E;
  29.  
  30. fscanf(f,"%d %d %d %d %d ", &V, &E, &R, &C, &X);
  31.  
  32.  
  33. struct Endpoint *endpoint;
  34. struct Video *videoclip;
  35. endpoint = (struct Endpoint *) malloc (10000 * sizeof(struct Endpoint));
  36. videoclip = (struct Video *) malloc (10000 * sizeof(struct Video));
  37.  
  38.  
  39. for(int i = 0; i < V; ++i)
  40. fscanf(f, "%d ", &videoclip[i].size);
  41.  
  42.  
  43.  
  44. for(int i = 0; i < V; ++i)
  45. printf("%d ", videoclip[i].size);
  46.  
  47.  
  48. for(int i = 0; i < E; ++i)
  49. {
  50. fscanf(f, "%d ", &endpoint[i].DataCenterLatency);
  51. fscanf(f, "%d ", &endpoint[i].NrCaches);
  52.  
  53. for(int j = 0; j < endpoint[i].NrCaches; ++j)
  54. fscanf(f,"%d %d ", &endpoint[i].Caches[j][0], &endpoint[i].Caches[j][1]);
  55. }
  56.  
  57. int req, idVid , endId;
  58.  
  59. for(int i = 0; i < E; ++i)
  60. endpoint[i].NrRequests = 0;
  61.  
  62. for(int i = 0; i < R; ++i)
  63. {
  64.  
  65. fscanf(f, "%d %d %d ", &idVid, &endId, &req);
  66. // printf("%d %d %d\n", idVid, endId, req);
  67. endpoint[endId].Requests[endpoint[endId].NrRequests][0] = idVid;
  68. endpoint[endId].Requests[endpoint[endId].NrRequests][1] = req;
  69. endpoint[endId].NrRequests++;
  70. }
  71. // printf("test");
  72. /////////AFISARE///////////////
  73.  
  74. /*
  75.  
  76. for(int i = 0; i < E; ++i)
  77. {
  78. printf("%d ", endpoint[i].DataCenterLatency);
  79. printf("%d\n", endpoint[i].NrCaches);
  80.  
  81. for(int j = 0; j < endpoint[i].NrCaches; ++j)
  82. printf("%d %d\n", endpoint[i].Caches[j][0], endpoint[i].Caches[j][1]);
  83. }
  84.  
  85. for(int i = 0; i < E; ++i) {
  86.  
  87. printf("%d %d %d\n",endpoint[i].Requests[endpoint[i].NrRequests][0],
  88. endpoint[i].Requests[endpoint[i].NrRequests][1],
  89. endpoint[i].NrRequests);
  90.  
  91. }
  92. */
  93.  
  94. // sortare
  95. printf("\n");
  96. int aux, i, j, k;
  97. for (i = 0; i < E; i++)
  98. for (j = 0; j < endpoint[i].NrCaches - 1; j++)
  99. for (k = j; k < endpoint[i].NrCaches; k++)
  100. if (endpoint[i].Caches[j][1] > endpoint[i].Caches[k][1])
  101. {
  102. aux = endpoint[i].Caches[j][1];
  103. endpoint[i].Caches[j][1] = endpoint[i].Caches[k][1];
  104. endpoint[i].Caches[k][1] = aux;
  105.  
  106. aux = endpoint[i].Caches[j][0];
  107. endpoint[i].Caches[j][0] = endpoint[i].Caches[k][0];
  108. endpoint[i].Caches[k][0] = aux;
  109. }
  110.  
  111. for (i = 0; i < E; i++)
  112. for (j = 0; j < endpoint[i].NrRequests - 1; j++)
  113. for (k = j; k < endpoint[i].NrRequests; k++)
  114. if (endpoint[i].Requests[j][1] < endpoint[i].Requests[k][1])
  115. {
  116. aux = endpoint[i].Requests[j][1];
  117. endpoint[i].Requests[j][1] = endpoint[i].Requests[k][1];
  118. endpoint[i].Requests[k][1] = aux;
  119.  
  120. aux = endpoint[i].Requests[j][0];
  121. endpoint[i].Requests[j][0] = endpoint[i].Requests[k][0];
  122. endpoint[i].Requests[k][0] = aux;
  123. }
  124.  
  125. for (i = 0; i < E; i++)
  126. {
  127. printf("-------------- %d -----------\n", i);
  128. printf("REQUESTS\n");
  129. for (j = 0; j < endpoint[i].NrRequests; j++)
  130. {
  131. printf("%d %d\n", endpoint[i].Requests[j][0], endpoint[i].Requests[j][1]);
  132. }
  133. printf("CACHES\n");
  134. for (j = 0; j < endpoint[i].NrCaches; j++)
  135. {
  136. printf("%d %d\n", endpoint[i].Caches[j][0], endpoint[i].Caches[j][1]);
  137. }
  138. }
  139.  
  140. fclose(f);
  141.  
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement