
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to find the number of refill packs to be bought
Suppose, there are 'a' number of matches and 'b' number of press conferences to be held in a stadium in a particular week. There are two cafeterias, one in the player dressing room and one in the press conference area. There are two soft drink dispensers in the cafeterias and they need to be filled at the start of the week. The dressing room cafeteria drink dispenser is used heavily, and it needs to be refilled after every 'c' games and the conference area cafeteria's dispenser needs to be refilled after every 'd' events. The stadium maintenance committee can order k drink refill packs at the beginning of each week, 'x' packs for the dressing room cafeteria, and 'y' packs for the conference room cafeteria where x + y <= k. Given the match schedule, we have to find out the values of x and y, and if more than k refill packs are needed, we print "Limit Exceeded".
So, if the input is like a = 8, b = 8, c = 4, d = 6, k = 9, then the output will be 2, 2.
Steps
To solve this, we will follow these steps −
a := (c + a - 1) / c b := (d + b - 1) / d if a + b <= k, then: print(a, b) Otherwise, print("Limit Exceeded")
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; #define N 100 void solve(int a, int b, int c, int d, int k) { a = (c + a - 1) / c; b = (d + b - 1) / d; if(a + b <= k) cout<<a<<" "<<b<<"\n"; else cout<<"Limit Exceeded."<<"\n"; } int main() { int a = 8, b = 8, c = 4, d = 6, k = 9; solve(a, b, c, d, k); return 0; }
Input
8, 8, 4, 6, 9
Output
2 2
- Related Articles
- C++ code to count number of packs of sheets to be bought
- C++ code to find out which number can be greater
- Program to find maximum number of package that can be bought by buyers in C++
- C++ code to find the number of scans needed to find an object
- C++ code to find out number of battery combos
- Maximum number of candies that can be bought in C
- C++ code to count number of times stones can be given
- C++ code to find the number of dial rotations to print a string
- C++ code to find number to disprove given prime hypothesis
- C++ code to find total number of digits in special numbers
- C++ code to find greater number whose factor is k
- Find the number of boxes to be removed in C++
- C++ code to check phone number can be formed from numeric string
- C++ code to count number of unread chapters
- C++ code to check triangular number
