[Mảng 1 Chiều Cơ Bản]. Bài 23. Mảng cộng dồn

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem source:
28Tech
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho mảng số nguyên A[] gồm N phần tử, nhiệm vụ của bạn là xây dựng mảng F cũng có N phần tử trong đó F[0] = A[0]F[i] = F[i -1] + A[i] với mọi i >= 1. Như vậy bạn thử nghĩ xem F[i] lưu giá trị gì?


Đầu vào

Dòng đầu tiên là số nguyên dương N

Dòng thứ 2 gồm N số nguyên viết cách nhau một vài khoảng trắng


Giới hạn

1<=N<=1000

0<=A[i]<=10^3


Đầu ra

In ra mảng cộng dồn F


Ví dụ :

Input 01
5
124 577 658 919 87
Output 01
124 701 1359 2278 2365

Comments

Please read the guidelines before commenting.



  • 0
    kietne  commented on Dec. 14, 2025, 11:57 a.m.

    CODE FULL AC CHO AE ĐÂY:

    include <bits/stdc++.h>

    using namespace std; using ll = long long;

    int main() { ios::syncwithstdio(false); cin.tie(nullptr); // viết code ở đây int n; cin >> n; vector<int> lt(n); for (int &i : lt) cin >> i; vector<int> f(n); f[0] = lt[0]; for (int i = 1; i < n; i++) { f[i] = f[i - 1] + lt[i]; } for (auto i : f) cout << i << " "; return 0; }


  • 0
    L8_DuongThanhKhiem  commented on Nov. 22, 2025, 4:25 a.m.

    Code C++ full AC cho bạn nào cần:

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int N;
        cin >> N;
        vector<int> A(N), F(N);
    
        for(int i = 0; i < N; i++) cin >> A[i];
    
        F[0] = A[0];
        for(int i = 1; i < N; i++){
            F[i] = F[i - 1] + A[i];
        }
    
        for(int i = 0; i < N; i++){
            cout << F[i] << " ";
        }
    }
    

  • -3
    hngoc  commented on July 4, 2025, 3:07 p.m.
    n=int(input())
    tmp=input().split()
    a=[]
    b=[]
    a.append(0)
    b.append(0)
    for x in tmp:
        a.append(int(x))
        b.append(0)
    for i in range(1,len(a)):
        b[i]=b[i-1]+a[i]
    for i in range(1,len(b)):
        print(b[i],end=' ')
    

  • -1
    bengokyeuanh99  commented on June 20, 2025, 6:41 a.m.

    include <stdio.h>

    int main() { int n; scanf("%d", &n);

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

    }


  • 0
    perkbevis2k4  commented on March 16, 2025, 3:39 p.m.

    include <iostream>

    define MAX 1000001

    using namespace std;

    long long a[MAX], sum[MAX], prefixSum[MAX];

    int main() { int n; cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        prefixSum[i] = prefixSum[i - 1] + a[i]; 
        cout << prefixSum[i] << " ";
    }
    return 0;
    

    }


  • 0
    bennie15025_meow  commented on Feb. 7, 2025, 2:03 p.m.

    include<bits/stdc++.h>

    using namespace std; long long a[1005],n,s=0; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; s+=a[i]; cout<<s<<" "; } }


  • -2
    Frekraiko  commented on Nov. 5, 2024, 1:28 p.m.

    include <bits/stdc++.h>

    using namespace std;

    int main() {

    int n;
    
    cin >> n;
    
    vector<int> a(n); 
    
    for (int i = 0 ; i < n ; i++) {
    
        cin >> a[i];
    
        F += a[i];
    
        cout << F << " ";
    
    }
    
    return 0;
    

    }


  • -20
    VuxPerfect  commented on June 9, 2024, 2:26 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.