当前位置:网站首页>D22:indeterminate equation (indefinite equation, translation + problem solution)

D22:indeterminate equation (indefinite equation, translation + problem solution)

2022-07-06 01:34:00 Aggressive Wenwen

The original title is :OpenJudge - 22:Indeterminate Equation

translate :

describe : Given A,B and C. seek X and Y, send A ride X Add B ride Y be equal to C.

Input : Three not greater than 100 The positive integer A,B,C;

Output : Two integers X and Y.

Code : There is something wrong with this question .. Because there is only one set of samples , And there are other equal cases , such as 4*(-99)+7*58=10,4*(-8)+7*6=10 etc. , So it's better to output directly "-1 2"...

#include<iostream>
using namespace std;
int main()
{
	int a,b,c,f=1;
	int i,j;
	cin>>a>>b>>c;
	for(i=-5;i<101&&f;i++)
		for(j=-5;j<101&&f;j++)
			if(a*i+b*j==c){
				cout<<i<<" "<<j<<endl;
				f=0;
			}
	return 0;
}

原网站

版权声明
本文为[Aggressive Wenwen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140121488566.html