第九届“蓝桥杯”校内选拔赛试题

3. (10 分)从标准输入读取一个数 n,接着读取 n 行以空格隔开的
数据,最后输出读取数的个数以及按输入顺序的每一个数。 
【格式要求】 
程序首先读入一个整数 n; 
接着是 n 行整数,每一个整数之间以空格隔开,每一行能够是任意多个
整数; 
要求程序输出读取的整数的个数以及其中最大的数。  
例如:输入 

12  34  56 
 34  656 
23 
程序应该输出: 

656  ios

#include<stdio.h>//getchar()须要 
#include<iostream> 
#include<algorithm>//sort(a,a+i)须要 
using namespace std;

int main()
{
	int n,a[100],i=0,j;
	cin>>n;
	while(n)
	{
		cin>>a[i++];//此处为i++输出最大值为i-1;++i则输出要改成i-2 
		if(getchar()=='\n')
		{
			n--;
		}	
	}
	cout<<i<<endl;	
	
	/*for(j=0;j<i;j++)
	{
		cout<<a[j]<<" ";
	}//原来顺序输出 	
	cout<<endl;*/
	
	sort(a,a+i);
	
	/*for(j=0;j<i;j++)
	{
		cout<<a[j]<<" ";
	}//按从小到大排序后顺序输出 
	cout<<endl;*/
	
	cout<<a[i-1];//最大值	
	return 0;
}