欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PAT1045

程序员文章站 2022-07-15 14:01:05
...
#include<iostream>
#include <iomanip>
#include <cstdio>
#include<string>
#include<vector>
#include<array>
#include<math.h>
#include <ctype.h>
#include<algorithm>
using namespace std;
int main()
{
	int c[100000];
	int i,n,max = 0,count = 0;
	cin >> n;
	vector<int > a(n), b(n);
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a.begin(), a.end());
	for (i = 0; i < n; i++)
	{
		if (b[i] == a[i] && b[i] > max)
			c[count++] = b[i];
		if (b[i] > max)
			max = b[i];
	}
	cout << count<<"\n";
	for (i = 0; i < count; i++)
	{
		if (i != count - 1)
			cout << c[i] << ' ';
		else
			cout << c[i];
	}
	cout <<"\n";
	return 0;
}

相关标签: PAT