My intention is after pushing pair
to vector temp_pairs
, compare it's 2 elements with the elements of the vector of vectors jumpers
, and if one element of temp_pairs
is equal to any element of jumpers
.clear()
the temp_pairs
.
The following code works, except for the 2 first pairs.
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
typedef std::vector<int> vector_i;
typedef std::vector<char> vector_c;
vector_c control {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','w','y','z',' ','.'};
std::vector<vector_c> jump_input();
int main()
{
jump_input();
return 0;
}
std::vector<vector_c> jump_input()
{
std::vector<vector_c> jumpers;
vector_c temp_pairs(2);
int jump_count = 0;
char in;
vector_c pair;
do
{
for (int i = 0; i < jumpers.size(); i++)
{
for (int j = 0; j < jumpers[i].size(); j++)
{
std::cout << jumpers[i][j];
}
std::cout << " ";
}
for (int i = 0; i < 2; i++)
{
std::cout << "\n" << "Enter the " << i+1 << " of the pair number "<< jumpers.size()+1 << "\n";
std::cin >> in;
for (int j = 0; j < control.size(); j++)
{
if (in == control[j])
{
pair.push_back(in);
}
}
}
if (pair.size()>1)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < control.size(); j++)
{
if (pair[i] == control[j])
{
temp_pairs.push_back(pair[i]);
}
}
}
}
// where the comparation happens
for (int i = 0; i < jumpers.size(); i++)
{
for (int j = 0; j < 2; j++)
{
if (jumpers[i][j] == temp_pairs[j])
{
temp_pairs.clear();
}
}
}
if (!temp_pairs.empty())
{
jumpers.push_back(temp_pairs);
jump_count += 1;
}
temp_pairs.clear();
pair.clear();
in='\0';
} while (jump_count<21);
return jumpers;
}
Terminal image enter image description here
I tried series of if statements and for loops, and this is the best result i code reach.