pat1045

第一版  2测试点后超时

#include <iostream>
#include <vector>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,count=0;
	bool b,c=true;
	vector<int> v;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	for(int i=0; i<n; i++)
	{
		b = true;
		for(int j=0; j<i; j++)
		{
			if(a[i]<=a[j])
			{
				b = false;
				break;
			}
		}

		for(int j=i+1; j<n; j++)
		{
			if(b)
			{
				if(a[i]>=a[j])
				{
					b = false;
					break;					
				}
			}
		}
		if(b)
		{
			count++;
			v.push_back(a[i]);
		}
	}
	cout<<count<<endl;
	vector<int>::iterator it;
	for(it=v.begin();it!=v.end();it++)
	{
		if(c)
		{
			cout<<*it;
			c=false;
		}
		else cout<<" "<<*it;
	}
	return 0;
}


原文地址:https://www.cnblogs.com/yunet/p/14967495.html