- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ code to find out if everyone will get ice cream
Suppose, there are three groups of people coming to a party. The first group of people likes butterscotch ice cream and do not like any other flavors of ice cream, the second group of people only dislikes strawberry ice cream and like every other flavor, and the third group likes all kinds of ice cream. Now, there are x people of the first group, y people of the second group, and z people of the third group are coming to a party, and everyone should have at least one icecream of their liking. The party organizers have brought a packs of butterscotch ice cream, b packs of chocolate ice cream, and c packs of strawberry ice cream. We have to find out if all the people at the party will be able to get one piece of their favorite ice cream or not.
So, if the input is like a = 6, b = 5, c = 5, x = 3, y = 8, z = 4, then the output will be Possible.
Steps
To solve this, we will follow these steps −
if a < x or a + b < x + y or a + b + c < x + y + z, then: print("Not Possible.") Otherwise print("Possible.")
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 x, int y, int z) { if (a < x || a + b < x + y || a + b + c < x + y + z) cout<<"Not Possible."; else cout<<"Possible."; } int main() { int a = 6, b = 5, c = 5, x = 3, y = 8, z = 4; solve(a, b, c, x, y, z); return 0; }
Input
6, 5, 5, 3, 8, 4
Output
Possible.