Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9. short unsigned int depth;
  10. short unsigned int numberCaught;
  11. /*long int numerator;
  12. long int denominator;*/
  13. Node* didntCatchNext;
  14. Node* didCatchNext;
  15. };
  16.  
  17. void fn(Node*, int);
  18. int array[50];
  19.  
  20. int main()
  21. {
  22. int ftarget;
  23. cout<<"Enter final target (try 100): ";
  24. cin>>ftarget;
  25. ofstream fout("output.txt");
  26.  
  27. for (int n=1; n<=50; n++)
  28. {
  29. for (int i=0; i<50; i++)
  30. array[i]=0;
  31.  
  32. Node *head, *iterator;
  33. head = new Node;
  34. iterator = head;
  35.  
  36. head->depth = 1;
  37. head->numberCaught = 1;
  38. /*head->numerator = 1;
  39. head->denominator = 1;*/
  40.  
  41. fn(iterator, n);
  42.  
  43. long int total=0;
  44. long int gt=0;
  45.  
  46. for (int i=0; i<50; i++)
  47. {
  48. if (i>25)
  49. gt+=array[i];
  50. total+=array[i];
  51. }
  52.  
  53. float fraction = (gt*100.0)/total;
  54. cout<<n<<": "<<fraction<<"%"<<endl;// ("<<gt<<"/"<<total<<")"<<endl<<endl<<endl;
  55. fout<<n<<": "<<fraction<<"%"<<endl;
  56. }
  57.  
  58. //system("pause");
  59. return 0;
  60. }
  61.  
  62. void fn(Node* node, int target)
  63. {
  64. if (node->depth == target)
  65. {
  66. array[node->numberCaught]++;
  67. //if (array[node->numberCaught]==1)
  68. // cout<<node->numberCaught<<endl;
  69. delete node;
  70. return;
  71. }
  72.  
  73. node->didntCatchNext = new Node;
  74. node->didntCatchNext->depth = node->depth + 1;
  75. node->didntCatchNext->numberCaught = node->numberCaught;
  76. /*node->didntCatchNext->numerator = node->numerator*node->numberCaught;
  77. node->didntCatchNext->denominator = node->denominator*26;*/
  78.  
  79. node->didCatchNext = new Node;
  80. node->didCatchNext->depth = node->depth + 1;
  81. node->didCatchNext->numberCaught = node->numberCaught + 1;
  82. /*node->didCatchNext->numerator = node->numerator*(26 - node->numberCaught);
  83. node->didCatchNext->denominator = node->denominator*26;*/
  84.  
  85. fn(node->didntCatchNext, target);
  86. fn(node->didCatchNext, target);
  87.  
  88. delete node;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement