标签:AC using stdio.h space main bsp 排序 ios mat
字符串内部排序
#include <iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
bool cmp(char str1,char str2 ){
return str1<str2;
}
int main(){
string str;
cin>>str;
sort(str.begin(),str.end(),cmp);
cout<<str;
return 0;
}
结构体排序
#include <iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
struct node{
int num;
string str;
}nd[10];
int cmp(node n1,node n2 ){
if(n1.num!=n2.num)
return n1.num<n2.num;
else if(n1.str.compare(n2.str)<0)
return 1 ;
else
return 0;
}
int main(){
for(int i =0;i<3;i++){
cin>>nd[i].num>>nd[i].str;
}
sort(nd,nd+3,cmp);
for(int j =0;j<3;j++){
cout<<nd[j].num<<" "<<nd[j].str<<endl;
}
return 0;
}
数组排序
#include <iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int cmp(int n1,int n2 ){
return n1<n2;
}
int main(){
int num[10];
for(int i =0;i<5;i++){
cin>>num[i];
}
sort(num,num+5,cmp);
for(int j =0;j<5;j++){
cout<<num[j]<<" ";
}
return 0;
}
标签:AC using stdio.h space main bsp 排序 ios mat
原文地址:https://www.cnblogs.com/cyj1258/p/9251663.html