qsort水一水结果2 9 10WA...

回复帖子

@LzXsbf 2019-04-10 22:59 回复

include <stdio.h>

include <string.h>

include <stdlib.h>

define Max 100010

typedef struct node{ char p; int pos; }Node; Node ans[Max]; char s[Max]; int cmp(const void a, const void b){ Node p1 = (Node )a; Node p2 = (Node *)b; return strcmp(p1->p, p2->p); } int main() { scanf("%s", s); int i; for(i = 0; s[i]; i++) ans[i] = (Node){s + i, i + 1};

qsort(ans, i, sizeof(Node), cmp);

for(int j = 0; j < i; j++)
    printf("%d%c", ans[j].pos, j != i - 1 ? ' ' : '\n');

return 0;

}

@LzXsbf 2019-04-10 23:07 回复 举报

include <stdio.h>

include <string.h>

include <stdlib.h>

define Max 100010

typedef struct node{

char *p;
int pos;

}Node;

Node ans[Max];

char s[Max];

int cmp(const void a, const void b) {

Node *p1 = (Node *)a;
Node *p2 = (Node *)b;
return strcmp(p1->p, p2->p);

}

int main() {

scanf("%s", s);
int i;
for(i = 0; s[i]; i++){
    ans[i] = (Node){s + i, i + 1};
}

qsort(ans, i, sizeof(Node), cmp);

for(int j = 0; j < i; j++)
    printf("%d%c", ans[j].pos, j != i - 1 ? ' ' : '\n');

return 0;

}

反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。