-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarm.cpp
37 lines (35 loc) · 796 Bytes
/
farm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
ifstream inStream;
int numTestCases;
inStream.open("input.txt");
if(inStream.fail())
{
cerr << "Input file opening failed.\n";
exit(1);
}
inStream >> numTestCases;
for (int i = 0; i<numTestCases; i++){
int a, b, n, w, sheep, goat;
inStream >> a >> b >> n >> w;
int count = 0;
for (int j = 1; j<n; j++){
if (a * j + b * (n-j) == w){
sheep = j;
goat = n-j;
count++;
}
}
if (count == 1){
cout << sheep << " " << goat <<endl;
}
else{
cout << "-1" <<endl;
}
}
inStream.close();
}