在线笔试--恶心的输入问题

Posted iamcdx-2017

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在线笔试--恶心的输入问题相关的知识,希望对你有一定的参考价值。

在线笔试,实在不懂为什么不直接像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 == ‘
‘)
		{
			m_array.push_back(tmp);
			tmp.clear();
		}
	}
	return 0;
}
int main()
{
	InputMutiint();
	system("pause");
	return 0;
}

  

以上是关于在线笔试--恶心的输入问题的主要内容,如果未能解决你的问题,请参考以下文章