OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
compare_cand.cpp File Reference
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

Go to the source code of this file.

Functions

void compare_cand (int *cand_n, int *cand_e, int ii_stok, int *cand_n_ref, int *cand_e_ref, int ii_stok_ref)

Function Documentation

◆ compare_cand()

void compare_cand ( int * cand_n,
int * cand_e,
int ii_stok,
int * cand_n_ref,
int * cand_e_ref,
int ii_stok_ref )

Definition at line 31 of file compare_cand.cpp.

32 {
33 std::vector<std::pair<int, int>> candidates, candidates_ref;
34 for (int i = 0; i < ii_stok; ++i)
35 {
36 candidates.emplace_back(cand_n[i], cand_e[i]);
37 }
38 for (int i = 0; i < ii_stok_ref; ++i)
39 {
40 candidates_ref.emplace_back(cand_n_ref[i], cand_e_ref[i]);
41 }
42
43 std::sort(candidates.begin(), candidates.end());
44 std::sort(candidates_ref.begin(), candidates_ref.end());
45
46 int num_matches = 0;
47 int i = 0, j = 0;
48 while (i < ii_stok && j < ii_stok_ref)
49 {
50 if (candidates[i] == candidates_ref[j])
51 {
52 num_matches++;
53 ++i;
54 ++j;
55 }
56 else if (candidates[i] < candidates_ref[j])
57 {
58 ++i;
59 }
60 else
61 {
62 ++j;
63 }
64 }
65 std::cout << "number of candidates: " << ii_stok << "(ref: "<<ii_stok_ref<<")\n";
66 if (num_matches == ii_stok_ref)
67 {
68 std::cout << "Success: All candidates_ref are found in candidates.\n";
69 }
70 else
71 {
72 std::cout << "Failure: Not all candidates_ref are found in candidates.\n";
73 }
74 }