关于stl的sort的cmp
  • 板块灌水区
  • 楼主CNCAGN
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/11/2 08:04
  • 上次更新2023/11/2 14:54:13
查看原帖
关于stl的sort的cmp
65161
CNCAGN楼主2023/11/2 08:04

为什么cmp里面不能写小于等于

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<functional>
#include<map>
using namespace std;
int red() {
	int op = 1, x = 0;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') {
			op = -1;
		}
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * op;
}
int a[100];
bool cmp(int a, int b) {
	return a <= b;
}
int main() {
	for(int i = 1; i <= 20; ++i) {
		a[i] = 1;
	}
	
	puts("--");
	for(int i = 1; i <= 20; ++i) {
		cout << a[i] << ' ' ;
	}
	puts("");
	puts("--");
	sort(a + 1, a + 21, cmp);
	puts("--");
	for(int i = 1; i <= 20; ++i) {
		cout << a[i] << ' ' ;
	}
	puts("--");
	return 0;
}

2023/11/2 08:04
加载中...