字符串排序函数--fsort()
用法:qsort(char *a,int len=strlen(a),sizeof(a[0]),int cmp);
具体代码如下:
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#include<cstring>
int cmp(const void *a, const void *b){return *(char*)a<*(char*)b;
}
int main(){char a[100];scanf("%s",a);qsort(a,strlen(a),sizeof(a[0]),cmp);for(int i=0;i<strlen(a);i++)printf("%c",a[i]);printf("\n");
}
对应输入输出:
ABCDEFG
GFEDCBA--------------------------------
Process exited after 4.677 seconds with return value 0
请按任意键继续. . .