Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NMAX 100000
- struct Video
- {
- int ok;
- int size;
- };
- struct Endpoint {
- int DataCenterLatency;
- int NrCaches;
- int Caches[NMAX][2];
- int NrRequests;
- int Requests[NMAX][2];
- };
- int main(int argc, char *argv[]) {
- FILE* f;
- f = fopen(argv[1], "r");
- // if (f == NULL)
- // return 0;
- int R,C,X;
- int V,E;
- fscanf(f,"%d %d %d %d %d ", &V, &E, &R, &C, &X);
- struct Endpoint *endpoint;
- struct Video *videoclip;
- endpoint = (struct Endpoint *) malloc (10000 * sizeof(struct Endpoint));
- videoclip = (struct Video *) malloc (10000 * sizeof(struct Video));
- for(int i = 0; i < V; ++i)
- fscanf(f, "%d ", &videoclip[i].size);
- for(int i = 0; i < V; ++i)
- printf("%d ", videoclip[i].size);
- for(int i = 0; i < E; ++i)
- {
- fscanf(f, "%d ", &endpoint[i].DataCenterLatency);
- fscanf(f, "%d ", &endpoint[i].NrCaches);
- for(int j = 0; j < endpoint[i].NrCaches; ++j)
- fscanf(f,"%d %d ", &endpoint[i].Caches[j][0], &endpoint[i].Caches[j][1]);
- }
- int req, idVid , endId;
- for(int i = 0; i < E; ++i)
- endpoint[i].NrRequests = 0;
- for(int i = 0; i < R; ++i)
- {
- fscanf(f, "%d %d %d ", &idVid, &endId, &req);
- // printf("%d %d %d\n", idVid, endId, req);
- endpoint[endId].Requests[endpoint[endId].NrRequests][0] = idVid;
- endpoint[endId].Requests[endpoint[endId].NrRequests][1] = req;
- endpoint[endId].NrRequests++;
- }
- // printf("test");
- /////////AFISARE///////////////
- /*
- for(int i = 0; i < E; ++i)
- {
- printf("%d ", endpoint[i].DataCenterLatency);
- printf("%d\n", endpoint[i].NrCaches);
- for(int j = 0; j < endpoint[i].NrCaches; ++j)
- printf("%d %d\n", endpoint[i].Caches[j][0], endpoint[i].Caches[j][1]);
- }
- for(int i = 0; i < E; ++i) {
- printf("%d %d %d\n",endpoint[i].Requests[endpoint[i].NrRequests][0],
- endpoint[i].Requests[endpoint[i].NrRequests][1],
- endpoint[i].NrRequests);
- }
- */
- // sortare
- printf("\n");
- int aux, i, j, k;
- for (i = 0; i < E; i++)
- for (j = 0; j < endpoint[i].NrCaches - 1; j++)
- for (k = j; k < endpoint[i].NrCaches; k++)
- if (endpoint[i].Caches[j][1] > endpoint[i].Caches[k][1])
- {
- aux = endpoint[i].Caches[j][1];
- endpoint[i].Caches[j][1] = endpoint[i].Caches[k][1];
- endpoint[i].Caches[k][1] = aux;
- aux = endpoint[i].Caches[j][0];
- endpoint[i].Caches[j][0] = endpoint[i].Caches[k][0];
- endpoint[i].Caches[k][0] = aux;
- }
- for (i = 0; i < E; i++)
- for (j = 0; j < endpoint[i].NrRequests - 1; j++)
- for (k = j; k < endpoint[i].NrRequests; k++)
- if (endpoint[i].Requests[j][1] < endpoint[i].Requests[k][1])
- {
- aux = endpoint[i].Requests[j][1];
- endpoint[i].Requests[j][1] = endpoint[i].Requests[k][1];
- endpoint[i].Requests[k][1] = aux;
- aux = endpoint[i].Requests[j][0];
- endpoint[i].Requests[j][0] = endpoint[i].Requests[k][0];
- endpoint[i].Requests[k][0] = aux;
- }
- for (i = 0; i < E; i++)
- {
- printf("-------------- %d -----------\n", i);
- printf("REQUESTS\n");
- for (j = 0; j < endpoint[i].NrRequests; j++)
- {
- printf("%d %d\n", endpoint[i].Requests[j][0], endpoint[i].Requests[j][1]);
- }
- printf("CACHES\n");
- for (j = 0; j < endpoint[i].NrCaches; j++)
- {
- printf("%d %d\n", endpoint[i].Caches[j][0], endpoint[i].Caches[j][1]);
- }
- }
- fclose(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement