Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- using namespace std;
- static long playGame(int ini, int n, int q) {
- long headctr = 0, tailCtr = 0;
- char *charr = new char [n];
- if(ini == 1)
- for (int i=0;i<n;i++) charr[i]='H';
- else
- for (int i=0;i<n;i++) charr[i]='T';
- for(int i=0; i<n; i++) {
- for(int j=0; j<=i; j++) {
- if(charr[j] == 'H')
- charr[j] = 'T';
- else
- charr[j] = 'H';
- }
- }
- for(int i=0; i<n; i++) {
- if(charr[i] == 'H') headctr++;
- else tailCtr++;
- }
- return (q==1)?headctr:tailCtr;
- }
- int main()
- {
- // cout<<"Hello World";
- int i,n,f;
- int t;
- while (t--)
- {
- int g;
- cin>>g;
- while (g--)
- {
- cin >>i>>n>>f;
- cout<<playGame(i,n,f);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment