I got this code that I'm working with. I need to take in inputs from command line and work with that input.
For example, I could have the input:
a 3 b 2 b 1 a 1 a 4 b 2
which will give the output:
1 3 4 1 2 2
My problem is that I can't use another input than of size 6 (or 12).
If I use the input
a 3 a 2 a 3
I will get the output:
2 3 3 3
but should get:
2 3 3
How can I have unknown size as an input without getting in trouble?
I am trying to solve the following question:
Read the datasets and write them into cout in the following order: first by dataset (first a, then b) and then by value. Example: input: a 3 b 2 b 1 a 1 a 4 b 2 output: 1 3 4 1 2 2
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <string>
#include <iterator>
#include <iomanip>
#include <vector>
using namespace std;
/*
input: a 3 b 2 b 1 a 1 a 4 b 2
output: 1 3 4 1 2 2
*/
//void insert_left
//void insert_right
//void Update
int main()
{
string my_vec_str;
double x;
vector<string> vect_string;
vector<int> vect_int;
bool go_on = true;
while (go_on)
{
cin >> my_vec_str;
cin >> x;
vect_string.push_back(my_vec_str);
vect_int.push_back(x);
if (cin.fail())
{
go_on = false;
}
if (vect_string.size() == 6 && vect_int.size() == 6)
{
go_on = false;
}
}
vector<int> vect_a;
vector<int> vect_b;
for (int i = 0; i < vect_string.size(); i++)
{
if (vect_string[i] == "a")
{
vect_a.push_back(vect_int[i]);
}
if (vect_string[i] == "b")
{
vect_b.push_back(vect_int[i]);
}
}
sort(vect_a.begin(), vect_a.end());
sort(vect_b.begin(), vect_b.end());
vector<int> vect_c;
for (int i = 0; i < vect_a.size(); i++)
{
vect_c.push_back(vect_a[i]);
}
for (int i = 0; i < vect_b.size(); i++)
{
vect_c.push_back(vect_b[i]);
}
for (auto &&i : vect_c)
{
cout << i << ' ';
}
return 0;
}