- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 number of standing spectators at time t
Suppose we have three numbers n, k and t. Amal is analyzing Mexican waves. There are n spectators numbered from 1 to n. They start from time 0. At time 1, first spectator stands, at time 2, second spectator stands. At time k, kth spectator stands then at time (k+1) the (k+1) th spectator stands and first spectator sits, at (k+2), the (k+2)th spectator stands but 2nd one sits, now at nth time, nth spectator stands and (n-k)th spectator sits. At time (n+1), the (n+1-k)th spectator sits and so on. We have to find the number of spectators stands at time t.
So, if the input is like n = 10; k = 5; t = 3, then the output will be 3, because before 5, no one will sit so all spectators from 1 to 3 are standing.
Steps
To solve this, we will follow these steps −
return minimum of t, k and (n + k - t)
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int n, int k, int t){ return min({ t, k, n + k - t }); } int main(){ int n = 10; int k = 5; int t = 3; cout << solve(n, k, t) << endl; }
Input
10, 5, 3
Output
3
- Related Articles
- Find the number of spectators standing in the stadium at time t in Python
- C++ code to count number of unread chapters
- How to calculate Execution Time of a Code Snippet in C++?
- C++ code to check triangular number
- Displaying T-code description and T-code field in Output ALV of report SM20 in SAP system
- C++ code to count number of weight splits of a number n
- C++ code to find out number of battery combos
- Short Time ("t") Format Specifier in C#
- Long Time ("T") Format Specifier in C#
- C++ code to find minimum time needed to do all tasks
- C++ code to count number of notebooks to make n origamis
- C++ code to count number of even substrings of numeric string
- C++ code to count number of packs of sheets to be bought
- C++ code to find total time to pull the box by rabbit
- C++ code to count number of times stones can be given
