3182. 字符串排序

单点时限: 2.0 sec

内存限制: 256 MB

$n$ $(1<n \leq 100)$ 个字符指针组成一个数组,每个指针指向一个字符串。通过该数组对其元素所指的字符串按以下顺序排序:按字符串中第一个数字字符的升序排序(不包含数字字符的字符串排在最前面)。若数字字符相同,则按字符串本身值的升序排序。使用 qsort 定义函数 SortStrings

只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。

不要改动测试程序。测试正确后,将测试程序和函数定义一起提交。

//********** Specification of SortStrings**********
void SortStrings(char *p[ ], int n);
/* PreCondition:
p points to an array with n pointers which point to strings
PostCondition:
array is sorted satisfying to the specification
*/

/***************************************************************/
/*                                                             */
/*  DON'T MODIFY main function ANYWAY!                         */
/*                                                             */
/***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define LEN 80
/********** Specification of SortStrings **********/
void SortStrings(char *p[], int n)
/* PreCondition:
p points to an array with n pointers which point to strings
PostCondition:
array is sorted satisfying to the specification
*/
{   //TODO: your function definition
}
/***************************************************************/
int main()
{   char s[N][LEN],*a[N];
    int n,i,t,cas;
    scanf("%d",&cas);
    for(t=0; t<cas; t++)
    {   scanf("%d",&n);
        getchar();
        for (i=0; i<n; i++) scanf("%s",a[i]=s[i]);
        /***** function SortStrings is called here *****/
        SortStrings(a,n);
        /****************************************/
        printf("case #%d:\n",t);
        for (i=0; i<n; i++) printf("%s%c",a[i],i<n-1?' ':'\n');
    }
    return 0;
}

273 人解决,307 人已尝试。

370 份提交通过,共有 1149 份提交。

2.2 EMB 奖励。

创建: 7 年,2 月前.

修改: 4 年,12 月前.

最后提交: 2 月前.

来源: N/A

题目标签