Cod sursa(job #1427978)

Utilizator stef93Stefan Gilca stef93 Data 3 mai 2015 13:55:57
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.87 kb
#include <stdio.h>
#include <stdlib.h>


FILE * open_file(const char * file, const char * opt)
{
	FILE * f = fopen(file, opt);

	if(f == NULL)
	{
		perror("Eroare");
		exit(EXIT_FAILURE);
	}

	return f;
}

char s;
int c, d;

void solve(int a, int b, int *x , int *y)
{
	int x0, y0;

	if(b == 0)
	{
		*x = 1;
		*y = 0;
		if(c % a != 0)
		{
			s = 0;
		}
		d = a;
		return;
	}

	solve(b, a%b, &x0, &y0);
	*x = y0;
	*y = x0 - (a/b) * y0;
}

int main()
{
	FILE *in = open_file("euclid3.in", "r");
	FILE *out = open_file("euclid3.out", "w");

	int n, a, b;
	int x, y;

	fscanf(in, "%d", &n);

	while(n--)
	{
		fscanf(in, "%d%d%d", &a, &b, &c);
		s = 1;
		solve(a, b, &x, &y);
		if(s == 1)
		{
			fprintf(out,"%d %d\n", x * (c/d), y*(c/d));
		}
		else
		{
			fprintf(out, "0 0\n");
		}
	}

	fclose(in);
	fclose(out);
	return 0;
}