[Mảng 1 Chiều Cơ Bản]. Bài 38. Tổng dãy số
View as PDF
Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Author:
Problem source:
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho mảng A[] gồm N phần tử, bạn hãy tính tổng của 2 số liên tiếp, 3 số liên tiếp, 4 số liên tiếp trong mảng.
Đầu vào
Dòng 1 là N : số phần tử trong mảng
Dòng 2 là N số trong mảng viết cách nhau 1 dấu cách
Giới hạn
4<=N<=1000
0<=A[i]<=1000
Đầu ra
Dòng 1 in ra tổng 2 số liên tiếp trong mảng
Dòng 2 in ra tổng 3 số liên tiếp trong mảng
Dòng 3 in ra tổng 4 số liên tiếp trong mảng
Ví dụ :
Input 01
8
5 17 4 17 2 13 7 14
Output 01
22 21 21 19 15 20 21
26 38 23 32 22 34
43 40 36 39 36
Comments
include<bits/stdc++.h>
using namespace std;
int a[1001];
int main(){
}
FULL AC: (khá giống giống sliding window)
include<bits/stdc++.h>
using namespace std;
int main(){
}
include<bits/stdc++.h>
using namespace std;
define ll long long
ll a[1123456],b[1123456],d1,d2,s,s1,s2,maxx=LLONGMIN,minn=LLONGMAX,maxx2=LLONGMIN,x,k,n,m; ll mark[11234567]; int main() { iosbase::syncwithstdio(false); cin.tie(nullptr); cin>>n; for(ll i=1; i<=n; i++) { cin>>a[i]; } for(ll i=2;i<=n;i++) { s=a[i]+a[i-1]; cout<<s<<" "; } cout<<'\n'; for(ll i=3;i<=n;i++) { s1=a[i]+a[i-1]+a[i-2]; cout<<s1<<" "; } cout<<'\n'; for(ll i=4;i<=n;i++) { s2=a[i]+a[i-1]+a[i-2]+a[i-3]; cout<<s2<<" "; } cout<<'\n'; return 0; }
include <bits/stdc++.h>
using namespace std; using ll = long long; using ull = unsigned long long;
int main() { ios::syncwithstdio(false); cin.tie(nullptr); int n; cin >> n; int a[n]; for (auto &i : a) cin >> i; for (int i = 0; i < n - 1; i++) { cout << a[i] + a[i + 1] << " "; } cout << "\n"; for (int i = 0; i < n - 2; i++) { cout << a[i] + a[i + 1] + a[i + 2] << " "; } cout << "\n"; for (int i = 0; i < n - 3; i++) { cout << a[i] + a[i + 1] + a[i + 2] + a[i + 3] << " "; }
}
oke predix sum
FULL AC
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.