A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms

 


Alice has a bucket of water initially having 

W litres of water in it. The maximum capacity of the bucket is X liters.

Alice turned on the tap and the water starts flowing into the bucket at a rate of Y litres/hour. She left the tap running for exactly Z hours. Determine whether the bucket has been overflown, filled exactly, or is still left unfilled.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases. The description of the test cases follows.
  • Each test case consists of a single line of input containing four space-separated integers W, X, Y, Z.

Output Format

For each test case, print the answer on a new line:

  • If the bucket has overflown print overflow
  • If it is exactly filled print filled
  • If it is still unfilled, print unfilled

You may print each character of the string in uppercase or lowercase (for example, the strings filledFIlledfiLLed, and FILLED will all be treated as identical).

Constraints

  • 1T1000
  • 1W,X,Y,Z1000

Subtasks

  • Subtask 1 (100 points):
    • Original constraints.

Sample Input 1 

4
1 2 3 4 
10 70 10 6 
2 100 4 3
4 3 2 1

Sample Output 1 

overFlow
filled
Unfilled
overflow



Explanation

Test case 1: Initially the bucket had 1 litre of water, we then added 3 litres of water for 4 hours. Thus, the total bucket inflow was 1+3×4=13 litres. Since this is greater than the capacity of 2 litres, the bucket will OVERFLOW

Test case 2: Initially the bucket had 10 litres of water, we then added 10 litres of water for 6 hours. Thus, the total bucket inflow was 10+10×6=70 litres. Since this is equal to the capacity of 70 litres, the bucket will be FILLED

Test case 3: Initially the bucket had 2 litres of water, we then added 4 litres of water for 3 hours. Thus, the total bucket inflow was 2+4×3=14 litres. Since this is lesser than the capacity of 100 litres, the bucket will be UNFILLED.

Test case 4: Initially the bucket had 4 litres of water, we then added 2 litres of water for 1 hours. Thus, the total bucket inflow was 4+2×1=6 litres. Since this is more than the capacity of 3 litres, the bucket will OVERFLOW.

solution in cpp

  1. #include<iostream>
  2. #define ll long long
  3. #include<vector>
  4. #include<stack>
  5. #include<string>
  6. #include<algorithm>
  7. using namespace std;

  8. void solve()
  9. {
  10. ll w, x, y, z, total;
  11. cin >> w >> x >> y >> z;
  12. total = w + (y * z);
  13. if (total == x)
  14. {
  15. cout << "filled\n";
  16. }
  17. else if (total > x)
  18. {
  19. cout << "overFlow\n";
  20. }
  21. else
  22. {
  23. cout << "Unfilled\n";
  24. }
  25. }

  26. int main()
  27. {
  28. int t;
  29. cin >> t;
  30. while (t--)
  31. {
  32. solve();
  33. }
  34. return 0;
  35. }

No comments:

Post a Comment