到目前为止,这是我的代码我想做的是说用户输入 1 2 3 然后按 -1,他或她将被要求输入另一组数字,比如 9 8 7,我的程序应该做什么将它们显示为 1 2 3 9 8 7,而是像这样显示它们 6 6 6 6 6 6,基本上它计算有多少数字并显示该数字的数量。那么任何人都可以在这里帮助我,我该如何制作才能显示两组数字的组合?
#include <iostream>
#include <vector>
using namespace std;
vector<int> append(vector<int> a, vector<int> b)
{
int n = a.size();
int m = b.size();
vector<int> c(n + m);
int i;
for (i = 0; i < n; i++)
c[i] = a[i];
for (i = 0; i < m; i++)
c[n + i] = b[i];
return c;
}
int main()
{
cout << "Please enter a set of numbers, insert -1 when done.\n";
vector<int>a;
bool more = true;
while (more)
{
int n;
cin >> n;
if (n == -1)
more = false;
else
a.push_back(n);
}
cout << "Please enter another set of numbers, insert -1 when done.\n";
vector<int>b;
more = true;
while (more)
{
int m;
cin >> m;
if (m == -1)
more = false;
else
b.push_back(m);
}
vector<int>d = append(a,b);
{
int i;
for (i= 0; i < d.size(); i++)
cout << d.size() << "\n";
}
}