文章

9

粉丝

1

获赞

35

访问

2.0k

头像
字符串排序3 题解:
P1261 北京大学机试题
发布于2025年3月13日 13:32
阅读数 156

在CodeBlocks上能正常运行,为啥在OJ上老是显示Presentation Error(格式错误),有大佬指点吗

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp(const void *a,const void*b){
char *pa=(char *)a;
char *pb=(char*)b;
return strlen(pa)-strlen(pb);
}
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int cnt=0;//用来存储本次输入实际上的数据大小
        char str[100][100];
        while(cnt<=n){
                gets(str[cnt]);
        if(strcmp(str[cnt],"stop")==0)
            break;
        else cnt++;
        }
        qsort(str,cnt,sizeof(char)*100,cmp);
        for(int i=0;i<cnt;i++)
           printf("%s\n",str[i]);
    }

}
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发