示例#1
0
文件: main.cpp 项目: bvdberg/code
void iterate() {
    printf("size = %d\n", numbers.size());
    NumbersIter iter;
    for (iter = numbers.begin(); iter != numbers.end(); ++iter) {
        printf("  %d\n", *iter);
    }
}
示例#2
0
文件: prime.cpp 项目: pettair/RSA
bool Prime::primality_test(const bignum & n, const integer & accuracy) {
    long_integer s = 0;
    bignum d(1);
    bignum a;
    bignum x;

    Numbers numbers;
    bignum n_minus_one(n - 1);
    bignum one(1);

    while ( n_minus_one % 2 == 0 ) {
        n_minus_one /= 2;
        s++;
    }

    d = n_minus_one;

    for(integer k = 0; k < accuracy; k++) {
        a = numbers.random(2, n - 1);
        x = modexp(a, d, n);

        if (x == one || x == n_minus_one) continue;

        for(long_integer r = 1; r <= s - 1; r++) {
            x = modexp(x, 2, n);

            if (x == one) return false;
            if (x == n_minus_one) continue;
        }

        return false;
    }

    return true; // possibly prime
}
示例#3
0
文件: main.cpp 项目: bvdberg/code
void find(int num) {
    NumbersIter iter = numbers.find(num);
    if (iter == numbers.end()) {
        printf("%d not found\n", num);
    } else {
        printf("%d found\n", num);
    }
}
示例#4
0
文件: prime.cpp 项目: pettair/RSA
bignum & Prime::generate_prime(const integer & length) {
    Numbers numbers;
    bignum * number = new BigUnsigned( numbers.random(length) );

    while ( !primality_test(*number, 4) )
        * number = numbers.random( length ); // or sth like: numbers.try_upgrading_to_prime( const bignum & number )

    return * number;
}
示例#5
0
bool ParallelComputeAverages(Numbers const &numbers, Averages &averages)
{
    if (numbers.empty())
    {
        return false;
    }


    // sort numbers for mode and median
    Numbers sorted = numbers;
    Averages avgResult;
    int modeResult;
    double medianResult;

    // sort numbers for median / mode
    tbb::parallel_sort(sorted);

    auto medianFunc = [&medianResult, &sorted]()
    {
        medianResult = ComputeMedian(sorted);
    };

    auto avgFunc = [&avgResult, &numbers]()
    {
        auto grainSize = numbers.size() / thread::hardware_concurrency();
        Averages avg{0, 0, 0, 0, 0, 0};
        avgResult = tbb::parallel_reduce(
                Range(numbers.begin(), numbers.end(), grainSize), avg,
                CalcIntermediateAverages,
                AddIntermediateAverages);
    };

    auto modeFunc = [&modeResult, &sorted]()
    {
        modeResult = ComputeMode(sorted);
    };

    // invoke parallel execution of calculations
    tbb::parallel_invoke(avgFunc, modeFunc, medianFunc);

    // set result
    double size = (double) numbers.size();
    averages.arithmeticMean = avgResult.arithmeticMean / size;
    averages.geometricMean = exp(avgResult.geometricMean / size);
    averages.harmonicMean = size / avgResult.harmonicMean;
    averages.quadraticMean = sqrt(avgResult.quadraticMean / size);
    averages.mode = modeResult;
    averages.median = medianResult;

    return true;
}
示例#6
0
bool ComputeAverages(Numbers const &numbers, Averages &averages)
{
    if (numbers.empty())
    {
        return false;
    }
    Numbers sortedNumbers = numbers;
    sort(sortedNumbers.begin(),
         sortedNumbers.end());  // sorting required for mode and median
    averages.mode = ComputeMode(sortedNumbers);
    averages.median = ComputeMedian(sortedNumbers);
    ComputeMeans(numbers, averages);
    return true;
}
示例#7
0
void InitRandom(Numbers &vec, size_t const nr, int max)
{
    auto rgen = std::bind(uniform_int_distribution<int>(1, max + 1),
                          default_random_engine((unsigned int) time(0)));
    vec.reserve(nr);
    generate_n(back_inserter(vec), nr, rgen);
}
示例#8
0
int main() {
    using namespace stable;
    using namespace beta;

    Numbers thenumbers;

    for (int j = 0; j < 100; j++)
    {
        thenumbers.add(j);
    }

    beta::dummyfunction(thenumbers);
    reverseprint(thenumbers);

    cout << "Hi!" << endl;

    return 0;
}
示例#9
0
int main()
{
  int tests;
  typedef map<string, int> Numbers;
  string x;
  int n;

  if(scanf("%d\n", &tests));

  for(int t = 0; t < tests; ++t)
  {
    cin >> n;

    Numbers nums;

    for(int i = 0; i < n; ++i)
    {
      cin >> x;
      sanitise(x);

      Numbers::iterator it = nums.find(x);
      if(it == nums.end())
      {
        it = nums.insert(Numbers::value_type(x, 0)).first;
      }
      it->second++;
    }

    Numbers::iterator it = nums.begin();

    bool found = false;

    if(t > 0) printf("\n");

    while(it != nums.end())
    {
      if(it->second > 1)
      {
        printf("%s %d\n", it->first.c_str(), it->second);
        found = true;
      }
      ++it;
    }

    if(!found)
    {
      printf("No duplicates.\n");
    }
  }

  return 0;
}
示例#10
0
文件: main.cpp 项目: bvdberg/code
void remove(int num) {
    NumbersIter iter = numbers.find(num);
    if (iter != numbers.end()) numbers.erase(iter);
}
示例#11
0
文件: main.cpp 项目: bvdberg/code
void add(int num) {
    numbers.insert(num);        
}
示例#12
0
文件: main.cpp 项目: argets08/School
int main(int argc, char** argv) {
    Numbers numList;
    cout << "Reading in sorted file" << endl;
    numList.readFile("sorted.txt");
    cout << "The total number of values in the Sorted array are " << numList.getCount() << endl;
    cout << "The 23rd value in the sorted file is" << numList.getValue(23) << endl;
    cout << "The biggest Value in the Sorted file is " << numList.findMax() << endl;
    cout << "The smallest number in the Sorted file is " << numList.findMin() << endl;
    cout << "The mean of numers in the Sorted array is " << numList.findMean() << endl;
    cout << "-----------------------------------------------" << endl;
    cout << "Reading in Un-sorted file" << endl;

    // cout << "TEST TEST TEST TEST" << endl;            //debug
    //  numList.Print();                             //debug

    numList.readFile("unsorted.txt");
    cout << "The total number of values in the  Unsorted array are " << numList.getCount() << endl;
    cout << "The 23rd value in the Unsorted file is" << numList.getValue(23) << endl;
    cout << "The biggest Value in the Unsorted file is " << numList.findMax() << endl;
    cout << "The smallest number in the Unsorted file is " << numList.findMin() << endl;
    cout << "The mean of numers in the Unsorted array is " << numList.findMean() << endl;
    cout << "-----------------------------------------------" << endl;

    // cout << "TEST TEST TEST TEST" << endl;            //debug
    //  numList.Print();                             //debug


    cout << " Homework 2.2 begins here" << endl;
    //hw 2.2
    numList.readFile("unsorted.txt");
    int checkEntry; //for dynamic use       //used 20899 as a test case
    cout << "Please enter number you wish to check for multiple occurances " << endl;
    cin >> checkEntry; //user entry
    cout << "number of times checkEntry comes up in unsorted file = " << numList.countValue(checkEntry) << endl;
    //cout << "number of times checkEntry comes up in sorted file = " << numList.countValue(20899) << endl;


    cout << "the index at which checkEntry comes up in the unSorted file = " << numList.lookupValue(checkEntry, 0, numList.getCount()) << endl;
    //cout << "the index at which 20899 comes up in the Sorted file = " << numList.lookupValue(20899, 0, numList.getCount()) << endl;


    return (EXIT_SUCCESS);
}
示例#13
0
void PrintNumbers(Numbers const &numbers)
{
    cout << "Numbers: ";
    copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
}
示例#14
0
 void reverseprint(Numbers num) {
     for (int i = num.getsize() - 1; i >= 0; i--) {
         cout << num[i] << " ";
     }
     cout << endl;
 }
示例#15
0
 void dummyfunction(Numbers num) {
     for (int i = 0; i < num.getsize(); i++) {
         cout << num[i] << endl;
     }
     cout << endl;
 }