Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unistd.h>
- #include <fstream>
- using namespace std;
- struct Node
- {
- short unsigned int depth;
- short unsigned int numberCaught;
- /*long int numerator;
- long int denominator;*/
- Node* didntCatchNext;
- Node* didCatchNext;
- };
- void fn(Node*, int);
- int array[50];
- int main()
- {
- int ftarget;
- cout<<"Enter final target (try 100): ";
- cin>>ftarget;
- ofstream fout("output.txt");
- for (int n=1; n<=50; n++)
- {
- for (int i=0; i<50; i++)
- array[i]=0;
- Node *head, *iterator;
- head = new Node;
- iterator = head;
- head->depth = 1;
- head->numberCaught = 1;
- /*head->numerator = 1;
- head->denominator = 1;*/
- fn(iterator, n);
- long int total=0;
- long int gt=0;
- for (int i=0; i<50; i++)
- {
- if (i>25)
- gt+=array[i];
- total+=array[i];
- }
- float fraction = (gt*100.0)/total;
- cout<<n<<": "<<fraction<<"%"<<endl;// ("<<gt<<"/"<<total<<")"<<endl<<endl<<endl;
- fout<<n<<": "<<fraction<<"%"<<endl;
- }
- //system("pause");
- return 0;
- }
- void fn(Node* node, int target)
- {
- if (node->depth == target)
- {
- array[node->numberCaught]++;
- //if (array[node->numberCaught]==1)
- // cout<<node->numberCaught<<endl;
- delete node;
- return;
- }
- node->didntCatchNext = new Node;
- node->didntCatchNext->depth = node->depth + 1;
- node->didntCatchNext->numberCaught = node->numberCaught;
- /*node->didntCatchNext->numerator = node->numerator*node->numberCaught;
- node->didntCatchNext->denominator = node->denominator*26;*/
- node->didCatchNext = new Node;
- node->didCatchNext->depth = node->depth + 1;
- node->didCatchNext->numberCaught = node->numberCaught + 1;
- /*node->didCatchNext->numerator = node->numerator*(26 - node->numberCaught);
- node->didCatchNext->denominator = node->denominator*26;*/
- fn(node->didntCatchNext, target);
- fn(node->didCatchNext, target);
- delete node;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement