个人对sort几种用法的总结

/*1.
------------------------------------------
sort 对字符型排序 
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int cmp(char a, char b){
	return a > b;
}
int main (){
	char a[10];
	scanf("%s", a);
	sort(a, a + 3,cmp);
	printf("%s\n", a);
	return 0;
}
------------------------------------------
*/



/*2.
------------------------------------------
sort对int型 排序 
# include<stdio.h>
# include<string.h>
# include<algorithm>
using namespace std;
int main()
{
	int a[3];
	int i,t;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	sort(a,a+3);
	for(i=0;i<3;i++) printf("%d",a[i]);
}
-------------------------------------------
*/



/*3.
-------------------------------------------

sort对浮点型排序 
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
int m,n,t,i;
int cmp(double a,double b){
	return a>b;
}
int main(){
	double a[5];
	for(i=0;i<5;i++) scanf("%lf",&a[i]);
	sort(a,a+5,cmp);
	for(i=0;i<5;i++) printf("%lf\n",a[i]);
	return 0;
}



-------------------------------------------
*/
/* 4.
-------------------------------------------
sort对字符型数组排序 
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
struct str
{
  int a;
  char c[5];	
}b[5];
int cmp(str x,str y)
{
	return strcmp(x.c,y.c)<0;
}
int main(){
	int m,n,t,i,s;
	scanf("%d",&m);
	for(t=0;t<m;t++)
	 scanf("%s",b[t].c);
	sort(b,b+m,cmp);
	for(t=0;t<m;t++)
	printf("%s\n",b[t].c);
	return 0;
}
-------------------------------------------- 
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值