Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 5 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Sep 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into master
  • Loading branch information
youngyangyang04 authored Sep 9, 2024
commit aeff1d6ad929949c5e15bfeaae2c7ca09247df62
45 changes: 45 additions & 0 deletions problems/kamacoder/0058.区间和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ if __name__ == "__main__":

```


### JavaScript

``` JavaScript
Expand Down Expand Up @@ -312,3 +313,47 @@ function prefixSum() {
```



### C

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

int main(int argc, char *argv[])
{
int num;
// 读取数组长度
scanf("%d", &num);

// 使用动态内存分配而不是静态数组,以适应不同的输入大小
int *a = (int *)malloc((num + 1) * sizeof(int));

// 初始化前缀和数组的第一个元素为0
a[0] = 0;

// 读取数组元素并计算前缀和
for (int i = 1; i <= num; i++)
{
int mm;
scanf("%d", &mm);
// 累加前缀和
a[i] = a[i - 1] + mm;
}

int m, n;
// 循环读取区间并计算区间和,直到输入结束
// scanf()返回成功匹配和赋值的个数,到达文件末尾则返回 EOF
while (scanf("%d%d", &m, &n) == 2)
{
// 输出区间和,注意区间是左闭右开,因此a[n+1]是包含n的元素的前缀和
printf("%d\n", a[n+1] - a[m]);
}

// 释放之前分配的内存
free(a);
return 0;
}

```

You are viewing a condensed version of this merge commit. You can view the full changes here.

AltStyle によって変換されたページ (->オリジナル) /