Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdlib.h>
- int *graph; /*一次元配列graph*/
- int n; /* 頂点の数 */
- #define graph_at(x, y) graph[((x)-1) * ((x)) / 2 + (y)]
- void inputgraph(void) /* グラフデータ読込み */
- {
- puts("頂点の数を入力してください");
- if (scanf("%d*[^\n]", &n) != 1) {
- n = 0;
- return;
- }
- graph = calloc(n * (n - 1) / 2, sizeof(*graph));
- for (int i = 0; i < n * (n - 1) / 2; ++i) {
- graph[i] = false;
- }
- puts("各辺の両端点を小さい順に番号で入力してください");
- {
- int x, y;
- while (scanf("%d%d*[^\n]", &y, &x) == 2) {
- graph_at(x, y) = true;
- }
- }
- }
- int main(void) {
- inputgraph(); /* 点の数 n, 辺の有無 graph[] を入力 */
- puts("入力データ graph(i,j)=F/T");
- for (int i = 0; i < n; ++i) {
- printf("%3d", i);
- for (int j = 0; j < i; ++j) {
- printf(" %c", (graph_at(i, j) ? 'T' : 'F'));
- }
- puts("");
- }
- fputs(" ", stdout);
- for (int i = 0; i < n; ++i)
- printf("%2d", i);
- puts("");
- free(graph);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement