为什么变长数组不能编译。。。

P1567 统计天数

你的markdown……
by Hoshino_Inc @ 2022-02-11 09:37:34


请不要强调自己的头文件 请正确使用md,多行代码必须另开一行
by HarunluoON @ 2022-02-11 09:42:44


```cpp #include <stdio.h> unsigned int count = 1, count_max, prev; int main() { unsigned int N, i; scanf("%u", &N); unsigned int p=new unsigned int[N]; for (i = 0; i < N; i++) scanf("%d", p + i); prev = p; for (i = 1; i < N; i++) { p++; if (*p > prev) { count++; } else { if (count > count_max) count_max = count; count = 0; } } printf("%d", count_max); return 0; } ```
by _l_l_ @ 2022-02-11 09:46:11


我草,这是啥马蜂
by __uint256_t @ 2022-02-11 09:48:45


@[c0nductor](/user/640961) ```cpp #include <stdio.h> unsigned int count = 1, count_max; unsigned int *prev; // 改为指针 int main() { unsigned int N, i; scanf("%u", &N); unsigned int* p=new unsigned int[N]; // 改为指针 for (i = 0; i < N; i++) scanf("%d", p + i); prev = p; for (i = 1; i < N; i++) { p++; if (*p > *prev) { // 改 count++; } else { if (count > count_max) count_max = count; count = 1; } prev = p; // 记得更新 prev 指针 } if (count > count_max) count_max = count; // 结尾也需要统计天数 printf("%d", count_max); return 0; } ```
by _l_l_ @ 2022-02-11 09:50:12


|