PAT1101 Quick Sort (25point(s))(做题记录)

Note:even the number is 0 we also have to cout<<endl in line2.(Or it can’t ac)(puzzling)

#include <iostream>
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <unordered_map>
#include <set>

using namespace std;

const int MAXN = 110000;
int s1[MAXN];
int s2[MAXN];
set<int> ans;
int N;

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
        scanf("%d",s1+i);
        s2[i]=s1[i];
    }    
	
    sort(s2, s2 + N);
	
    int max=-1;
    
	for (int i = 0; i <N; i++)
	{
		if (s2[i] == s1[i]&&s1[i]>max) ans.insert(s2[i]);
        if(s1[i]>max) max=s1[i];
	}
	
    cout << ans.size() << endl;
	
	bool first = true;

	for (auto &a : ans)
	{
		if (first) { cout << a; first = false; }
		else cout <<" "<< a;		
	}
	//if(ans.size()!=0) 
        cout << endl;

    return 0;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值