利用字符串流快速读取数据

Input

第1行输入一个数n

第2~n+1行输入若干个整数

Output

将输入的n行整数重新输出

Sample Input

3
6 7
4 7 3 6
2 1 3 5

Sample Output
6 7
4 7 3 6
2 1 3 5

思路:一般我们会用字符串读取一整行,再找出其中的数字,但如果利用字符串流的话可以快速读入每行数字

代码如下:

#include
using namespace std;

int main() {
	int n;
	cin >> n;
	getchar();
	string str;

	for (int i = 0; i < n; i++) {
		getline(cin, str);
		stringstream ss(str);
		int t = 0;
		while (ss >> t)cout<

你可能感兴趣的:(算法竞赛,c++,算法)