poj 1007(sort函数的重写)
作者:互联网
#include<iostream> #include<cstring> #include<string> #include<algorithm> using namespace std; string data[105]; int data_num[105]; int nixushu(string a){ int num = 0; for(int j=0;j<a.length();j++){ for(int k=j+1;k<a.length();k++){ if(a[j]>a[k]){ num++; } } } return num; } bool cmp(string a,string b){ return nixushu(a)<=nixushu(b); } int main(){ int n,m; memset(data_num,0,sizeof(data_num)); scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ cin>>data[i]; } sort(data,data+m,cmp); for(int i=0;i<m;i++){ cout<<data[i]<<endl; } return 0; }
标签:sort,string,int,num,poj,1007,include,data 来源: https://www.cnblogs.com/stevenzrx/p/15519821.html