C++ Builder

Moderators: Lundin
Number of threads: 518
Number of posts: 1158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to compare values in vector to an other vector Posted by Theisonews on 24 Apr 2011 at 8:34 AM
Hey all.

Please help. i been at it all night and i cant figure it out. Its been 2 years since i last programmed in c++.

my program has 1 array with 30, 3-1 digit numbers i .e 346 , 345 ,377 etc

i will have 13 vectors i will call vector<int> First_tier(345,358, etc)
Second Tier etc()

i want the program to find any of the series of numbers that is in the array to find it an any of the vectors. and i want it to tell me what vector it was found it.

also the order of the series shoudlnt matter for example 123 is the same as 321 or 213.

this is what i got so far. i commented most of the code out.
#include<iostream>
#include <vector>
#include <algorithm>


using namespace std;

bool myfunction (int i,int j) { return (i<j); }

int main()

{
    // the series of numbers  to be found in the vectors below
   int previous_pick_3_numbers[20]={346,794,861,529,347,925,196,969,243,837,740,025,822,809,454,843,942,510,573,346};
  // 13 vectors
    vector<int> firsts_tier(409 , 508 , 509, 607, 608 ,707 , 139 , 148 , 149 , 157 , 158 ,166 , 167 ,229 , 238 , 239 ,247 , 248 ,256 ,257 ,266 ,337 ,338 ,346 ,347 , 355 , 356 , 445 , 446 ,455);
    vector<int> seconds_tier(309 , 408 , 507 , 606 , 609 ,708 ,129 ,138 , 147 , 156 , 159 ,168 ,177 , 228 , 237 , 246 , 249 , 255 , 258 , 267 , 336 , 339 , 345 , 348 , 357 , 366 , 444 , 447 , 456 , 555);
    /*vector<int> thirds_tier(209,308,407,506,709,808,119,128,137,146,155,169,178,227,236,245,259,268,277,335,344,349,358,367,448,457,466,556);
    vector<int> fourths_tier(208,307,406,505,809,118,127,136,145,179,188,226,235,244,269,278,334,359,368,377,449,458,467,557,566);
    vector<int> fifths_tier(900,108,207,306,405,909,117,126,135,144,189,225,234,279,288,333,369,378,459,468,477,558,567,666);
    vector<int> sixths_tier(800,107,206,305,404,116,125,134,199,224,233,289,379,388,469,478,559,568,577,667);
    vector<int> sevenths_tier(700,106,205,304,115,124,133,223,299,389,479,488,569,578,668,677);
    vector<int> eighths_tier(600,105,204,303,114,123,222,399,489,579,588,669,678,777);
    vector<int> ninths_tier(500,104,203,113,122,499,589,679,688,778);
    vector<int> tenths_tier(400,103,202,112,599,689,779,788);
    vector<int> elevenths_tier(300,102,111,699,789,888);
    vector<int> twelves_tier(200,101,799,889);
    vector<int> thirteenths_tier(100,899,999); */
    
    


  
 vector<int> copy_of_array(previous_pick_3_numbers,previous_pick_3_numbers+20);                         // 1 2 3 4 5 4 3 2 1

  // using default comparison:
  sort (firsts_tier.begin(), firsts_tier.end());

 
  if (binary_search (firsts_tier.begin(), firsts_tier.end(), copy_of_array;))
    cout << "found!\n"; else cout << "not found.\n";

  // using myfunction as comp:
  sort ( firsts_tier.begin(),  firsts_tier.end(), myfunction);

  cout << "looking for a ... ";
  if (binary_search (seconds_tier.begin(), seconds_tier.end(), copy_of_array, myfunction))
    cout << "found!\n"; else cout << "not found.\n";
    
    return 0;
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.