Guest User

Untitled

a guest
Oct 19th, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7. const int messageSize = 5;
  8. const char message2[] = {'L','i','n','k','y'};
  9. const string message1[] = {"You'll", "never", "see", "him", "again"};
  10.  
  11.  
  12. void initialize(list<string> &first, list<char> &second, list<int> &third, list<unsigned long> &fourth)
  13. {
  14.         srand(time(NULL));
  15.  
  16.         //create 5 string links in first
  17.         for(int i=0; i < messageSize; i++)
  18.         {
  19.                 first.push_front(message1[rand()%5]);
  20.         }
  21.  
  22.         //iterate and add linking at rand2 location
  23.         for(int i = 0; i < messageSize; i++)
  24.         {
  25.                 second.push_front(message2[i]);
  26.                 second.push_back(message2[i]);
  27.         }
  28.  
  29.         //put random ints in the thrid list
  30.         for(int i = 0; i < messageSize*2; i++)
  31.         {
  32.                 third.push_front(rand()%100);
  33.         }
  34.  
  35.         //put random longs in the last list
  36.         for(int i = 0; i < 100; i++)
  37.         {
  38.                 fourth.push_front( (unsigned long) rand()*123456789+100000000 );
  39.         }
  40.  
  41. }
  42.  
  43. void kidnap(list<string> &stringList)
  44. {
  45.         //hide linky in list by iterating through the begining of the list
  46.         //and setting the node at a random location to the string "Linky"
  47.  
  48.         //First get the size of the list, call it size
  49.         //Second get a random location within that size
  50.  
  51.         int size = stringList.size();
  52.         int location = rand()%size;
  53.         list<string>::iterator itr = stringList.begin();
  54.  
  55.         while(location > 0) {
  56.                 itr++;
  57.                 location--;
  58.         }
  59.  
  60.         //The insert function
  61.         list<string>::iterator itr2;
  62.         itr2 = stringList.insert(itr, "Linky");
  63. }
  64.  
  65. unsigned long search(list<string> &first, list<char> &second, list<int> &third, list<unsigned long> &fourth)
  66. {
  67.  
  68. //Clue 1
  69. //Search the first list for the string "Linky" this index will refer to which character in the
  70. //word linky we are looking for
  71.  
  72.  
  73. //Clue 2
  74. //look for the letter found in clue 1 in the second list
  75.  
  76.  
  77. //Clue 3
  78. //find the nth number in the integer list counting from the back(n is from clue 2)
  79.  
  80.  
  81. //Clue 4
  82. //The value in clue 3 refers to the location of the combination it is the xth largest
  83. //number in the list. To find it sort the list and iterate through it.
  84.  
  85.  
  86. }
  87.  
  88.  
  89. int main() {
  90.  
  91.         //create four lists
  92.         list<string> stringList;
  93.         list<char> charList;
  94.         list<int> intList;
  95.         list<unsigned long> longList;
  96.  
  97.         //use this function to initialize all of them
  98.         initialize(stringList, charList, intList, longList);
  99.  
  100.         //create an iterator for each list
  101.         list<string>::iterator itS;
  102.         list<char>::iterator itC;
  103.         list<int>::iterator itI;
  104.         list<unsigned long>::iterator itL;
  105.  
  106.         //answer
  107.         unsigned long combination;
  108.  
  109.         //kidnap linky
  110.         kidnap(stringList);
  111.  
  112.  
  113.         //PRINT THE LISTS
  114.  
  115.         for (itS=stringList.begin(); itS!=stringList.end(); itS++) {
  116.                         cout << " " << *itS;
  117.         }
  118.  
  119.         cout << endl;
  120.  
  121.         for (itC=charList.begin(); itC!=charList.end(); itC++) {
  122.                 cout << " " << *itC;
  123.         }
  124.  
  125.         cout << endl;
  126.  
  127.         for (itI=intList.begin(); itI!=intList.end(); itI++) {
  128.                 cout << " " << *itI;
  129.         }
  130.  
  131.         cout << endl;
  132.  
  133.         for (itL=longList.begin(); itL!=longList.end(); itL++) {
  134.                 cout << " " << *itL;
  135.         }
  136.         cout << endl;
  137.  
  138.         //here is the answer
  139.         combination = search(stringList, charList, intList, longList);
  140.         cout << "The code for the safe deposit box is: " << combination << endl;
  141.  
  142.         return 0;
  143. }
  144.  
  145.  
Advertisement
Add Comment
Please, Sign In to add comment