Guest User

Untitled

a guest
Apr 28th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. static long playGame(int ini, int n, int q) {
  14. long headctr = 0, tailCtr = 0;
  15. char *charr = new char [n];
  16.  
  17. if(ini == 1)
  18. for (int i=0;i<n;i++) charr[i]='H';
  19. else
  20. for (int i=0;i<n;i++) charr[i]='T';
  21.  
  22. for(int i=0; i<n; i++) {
  23. for(int j=0; j<=i; j++) {
  24. if(charr[j] == 'H')
  25. charr[j] = 'T';
  26. else
  27. charr[j] = 'H';
  28. }
  29. }
  30. for(int i=0; i<n; i++) {
  31. if(charr[i] == 'H') headctr++;
  32. else tailCtr++;
  33. }
  34. return (q==1)?headctr:tailCtr;
  35. }
  36.  
  37. int main()
  38. {
  39. // cout<<"Hello World";
  40. int i,n,f;
  41. int t;
  42. while (t--)
  43. {
  44. int g;
  45. cin>>g;
  46. while (g--)
  47. {
  48. cin >>i>>n>>f;
  49.  
  50. cout<<playGame(i,n,f);
  51. }
  52. }
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment