Codechef Fill the Bucket problem solution

In this Fill the Bucket problem we have a Bucket having a capacity of K liters. It is already filled with X liters of water. we need to find the maximum amount of extra water in liters that can fill in the bucket without overflowing the bucket.

fill the bucket problem solution


Problem solution in C programming.

#include <stdio.h> int main(void) { int n,a,b; scanf("%d",&n); while (n--) { scanf("%d%d",&a,&b); printf("%d\n",a-b); } return 0; }


Here is the above code first we read an integer number N that's the number of a test case. and after that, we run a loop till then N got negative. and in the loop, we scan each test case value and print the amount of water that we need to fill in the bucket.

Problem solution in C++ programming.

#include <iostream> using namespace std; int main() { // your code goes here int t; cin>>t; while(t--) { int k,x; cin>>k; cin>>x; cout<<k-x<<endl; } return 0; }


Here in the above C++ code first we read an integer t for the test cases. and then we run a while loop to read all the test cases and print the amount of extra water we need to fill the bucket.

Problem solution in Java programming.

import java.util.*; class FBC { public static void main(String args[]){ Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0){ int x=sc.nextInt(); int y=sc.nextInt(); System.out.println(x-y); } } }


Problem solution in Python programming.

t=int(input()) for _ in range(t): k,x=map(int,input().split()) y=k-x print(y)



Post a Comment

0 Comments