在线笔试,实在不懂为什么不直接像leetcode 那样,直接给出测试API 参数,接口样例,非要有一步自己从键盘获取输入参数。
以下,持续记录吧:
(1)从键盘录入多行数据,每行的多个整数作为一个数组形式存储.
示例输入:
1,2,3
4,5
7,8,9
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
//输入多行数组
int InputMutiint()
{
std::vector < std::vector<int> > m_array;
std::vector<int> tmp;
int a;
char c;
while (std::cin >> a)
{
tmp.push_back(a);
c = getchar();
if (c == '\n')
{
m_array.push_back(tmp);
tmp.clear();
}
}
return 0;
}
int main()
{
InputMutiint();
system("pause");
return 0;
}