指標_最後的元素2 還是錯的

 avatar
user_3763047219
c_cpp
2 years ago
1.3 kB
1
Indexable
Never
int extractMax(int* stone, int stoneSize);
void insert(int* stone, int stoneSize, int value);
int lastStoneWeight(int* stones, int stonesSize);


int extractMax(int* stone, int stoneSize) {
    int y = 0;
    int yi = 0;
    for (int i = 0; i < stoneSize;i++) {
        if (y < *stone) {
            y = *stone;
            yi = i;
            stone++;
        }
    }
    stone = stone - stoneSize;
    int x = 0;
    int xi = 0;
    for (int i = 0; i < stoneSize; i++) {
        if (x < *stone && i!=yi) {
            x = *stone;
            xi = i;
            stone++;
        }
    }
    if (x == y) {
        if (xi < yi) {
            stone = stone + xi;
            for (int i = xi; i < yi-1; i++) {
                *stone = *(stone + 1);
                stone++;
            }
            for(int i=yi;i<stoneSize;i++)
        }
    }
}

void insert(int* stone, int stoneSize, int value) {
}

int lastStoneWeight(int* stones, int stonesSize) {

}


#include <stdio.h>
#include <stdlib.h>


int main() {
    int n = 0;
    int ans;
    scanf("%d", &n);
    int* a = (int*)malloc(n * sizeof(int));

    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    ans = lastStoneWeight(a, n);
    printf("%d", ans);
    free(a);
    return 0;
}