回复 10楼 九转星河
C99的VLA 了解一下
https://zh.
#include<stdio.h> int comp( const void*,const void* ); unsigned fun( unsigned,unsigned ); unsigned print( const char* ); int main( void ) { unsigned a; unsigned b; if (scanf("%u%u",&a,&b)!=2) return 1; printf("%u\n",fun(a,b)); return 0; } int comp( const void* p,const void* q ) { return *( char* )q-*( char* )p; } #include<stdlib.h> #include<string.h> #include<assert.h> unsigned fun( unsigned a,unsigned b ) { unsigned count; char* p=( char* )calloc( ( unsigned )(-~( int )a),b);//-~a=a+1 assert(p); memset(p,-1,b); qsort(p,( unsigned )(-~( int )a),b,comp); count=print(p); free(p); return count; } unsigned print( const char* p ) { unsigned i=0; while (*p++==0) ++i; return i; }
[此贴子已经被作者于2018-6-7 11:33编辑过]