Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : 定義主控台應用程式的進入點。
- //
- #include <stdio.h>
- #include<stdbool.h>
- #include<stdlib.h>
- int compare(const void *a, const void *b)//這函式是 qsort 所需的比較函式
- {
- return *(int*)a - *(int*)b; //傳回 1 代表 a>b
- }
- int main()
- {
- int a;
- while (scanf("%d", &a) != EOF)
- {
- int *x = (int*)malloc(sizeof(int)*a);
- int *y = (int*)malloc(sizeof(int)*a);
- int start, end, which, rank = 0,big=-100000;
- for (int i = 0; i < a; i++)
- {
- scanf("%d", x + i);
- }
- scanf("%d %d %d", &start, &end, &which);
- qsort((void*)(a+start), end - start + 1, sizeof(int),compare);
- for (int i = 0; i < a; i++)
- {
- printf("%d ", x + i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment