如何读取输入并将其拆分为Vector

时间:2019-05-27 18:19:58

标签: c++ arrays vector cin

我有一组整数,2 56, 76, 4, 99,并且希望基于“空格”定界符将它们解析为vector<int>。我没有C ++读取C#中“ Console.ReadLine()”所做的输入的经验。对于下面的代码片段,我如何读取用户输入为cin,然后将其转换为向量

int main()
{
 //Read user input here as "`2 56, 76, 4, 99`"
 //Then based on "space" break it into vector<int> a = {2 56, 76, 4, 99};
vector<int> a = {121,23,3,333,4};
int memo[1<<10];
for (int i = 0; i < 1 << 10; i++) memo[i] = -1;

 int res = 0;
 for (int i = 0; i < 1 << 10; i++) {
 res = std::max(res, dp(i, memo, a));
 }
 cout << res << std::endl;

 return 0;
}

道歉,如果做起来太简单,那是我的第一个与alogorithms相关的C ++程序。

0 个答案:

没有答案
相关问题