Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int** readInput(int& N, int rows, int columns)
- {
- int** G = new int*[rows];
- for(int i = 0; i < rows; i++)
- {
- G[i] = new int[columns];
- memset(G[i], -1, sizeof(int)*columns);
- }
- FILE* file = fopen("C:\\Users\\Chimney\\Desktop\\input.txt","r");
- fscanf(file,"%d\n", &N);
- int x, y, value;
- while(fscanf(file,"%d %d %d\n", &x, &y, &value) == 3)
- {
- //printf("input %d %d %d\n", x, y, value);
- G[x][y] = value;
- G[y][x] = value;
- }
- //debug
- for(int i = 0; i < 100; i++)
- for(int j = 0; j < 100; j++)
- {
- printf(" G[%d][%d]= %d\n", i, j, G[i][j]);
- }
- fclose(file);
- return G;
- }
- int main()
- {
- int** G = NULL;
- int N;
- G = readInput(N, 100, 100);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement