Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- const int messageSize = 5;
- const char message2[] = {'L','i','n','k','y'};
- const string message1[] = {"You'll", "never", "see", "him", "again"};
- void initialize(list<string> &first, list<char> &second, list<int> &third, list<unsigned long> &fourth)
- {
- srand(time(NULL));
- //create 5 string links in first
- for(int i=0; i < messageSize; i++)
- {
- first.push_front(message1[rand()%5]);
- }
- //iterate and add linking at rand2 location
- for(int i = 0; i < messageSize; i++)
- {
- second.push_front(message2[i]);
- second.push_back(message2[i]);
- }
- //put random ints in the thrid list
- for(int i = 0; i < messageSize*2; i++)
- {
- third.push_front(rand()%100);
- }
- //put random longs in the last list
- for(int i = 0; i < 100; i++)
- {
- fourth.push_front( (unsigned long) rand()*123456789+100000000 );
- }
- }
- void kidnap(list<string> &stringList)
- {
- //hide linky in list by iterating through the begining of the list
- //and setting the node at a random location to the string "Linky"
- //First get the size of the list, call it size
- //Second get a random location within that size
- int size = stringList.size();
- int location = rand()%size;
- list<string>::iterator itr = stringList.begin();
- while(location > 0) {
- itr++;
- location--;
- }
- //The insert function
- list<string>::iterator itr2;
- itr2 = stringList.insert(itr, "Linky");
- }
- unsigned long search(list<string> &first, list<char> &second, list<int> &third, list<unsigned long> &fourth)
- {
- //Clue 1
- //Search the first list for the string "Linky" this index will refer to which character in the
- //word linky we are looking for
- //Clue 2
- //look for the letter found in clue 1 in the second list
- //Clue 3
- //find the nth number in the integer list counting from the back(n is from clue 2)
- //Clue 4
- //The value in clue 3 refers to the location of the combination it is the xth largest
- //number in the list. To find it sort the list and iterate through it.
- }
- int main() {
- //create four lists
- list<string> stringList;
- list<char> charList;
- list<int> intList;
- list<unsigned long> longList;
- //use this function to initialize all of them
- initialize(stringList, charList, intList, longList);
- //create an iterator for each list
- list<string>::iterator itS;
- list<char>::iterator itC;
- list<int>::iterator itI;
- list<unsigned long>::iterator itL;
- //answer
- unsigned long combination;
- //kidnap linky
- kidnap(stringList);
- //PRINT THE LISTS
- for (itS=stringList.begin(); itS!=stringList.end(); itS++) {
- cout << " " << *itS;
- }
- cout << endl;
- for (itC=charList.begin(); itC!=charList.end(); itC++) {
- cout << " " << *itC;
- }
- cout << endl;
- for (itI=intList.begin(); itI!=intList.end(); itI++) {
- cout << " " << *itI;
- }
- cout << endl;
- for (itL=longList.begin(); itL!=longList.end(); itL++) {
- cout << " " << *itL;
- }
- cout << endl;
- //here is the answer
- combination = search(stringList, charList, intList, longList);
- cout << "The code for the safe deposit box is: " << combination << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment