算法竞赛中烦人的输入输出
一、将一行以空格为分隔符的数据读入数组
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int a[10];
int n = 0;
string line;
getline(cin,line);
stringstream ssin(line);
while (ssin >> a[n]) n++;
for (int i =0 ; i < 5; i++)
cout << a[i];
return 0;
}
二、读入和打印特殊格式的数据
#include<iostream>
#include<cstdio>
#include<sstream>
using namespace std;
int main()
{
int a, b, c;
string line;
getline(cin, line);
sscanf_s(line.c_str(), "%d:%d (%d)", &a, &b, &c);
printf("%02d:%02d (%02d)",a,b,c);
return 0;
}