0% found this document useful (0 votes)
10 views

Baitap6 CPP

Uploaded by

baobui03022010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Baitap6 CPP

Uploaded by

baobui03022010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Bài 1:

#include <bits/stdc++.h>

using namespace std;

int main() {

long long a[1000],b[1000],n,m,t=0,r=0;

cin>>n;

for (int i = 0; i < n; i++)cin >> a[i];

t=a[1]+a[2]+a[0];

m = t;

for (int i = 3; i < n; ++i) {

t += a[i]-a[i-3];

if (t > m) {

m = t;}}

cout << m << endl;

return 0;

Bài 2: #include<bits/stdc++.h>

using namespace std;

int main() {

int n, a[1000], b[1000];

cin >> n;

for(int i=0;i<n; i++) {

cin >> a[i];

b[i] = 1;}

for(int i=n-1; i>0; i--) { if(a[i] == a[i-1]) b[i-1] += b[i];}

int i=0;

while (i < n) {

if(b[i] != 1) {

for(int j=i; j <i+b[i]; j++)


cout << a[j] << " ";

cout<<endl;

i += b[i];} else i++;}

return 0;

Bài 3: #include <bits/stdc++.h>

using namespace std;

int main() {

int n, a[1000], b[1000],t=0;

cin >> n;

for(int i=0; i < n; i++) {

cin >> a[i];b[i] = 1;}

for(int i=n-1; i>0; i--) {

if(a[i] == a[i-1]) b[i-1] += b[i];}

int m = b[0];

for (int i=1; i<n; i++) {if(m < b[i]) m = b[i];}

cout << m << endl;

for (int i = 0; i < n; i++) {

if(b[i] == m) t = i;}

for (int i = t; i < t+ m; i++) {cout << a[i] << " ";}

return 0;

Bài 4: #include <bits/stdc++.h>

using namespace std;

int main() {

long long a[1000],b[1000],k,n,m,d=0;

cin>>n>>k;

for (int i = 0; i < n; i++){cin >> a[i];

for (int j = 0; j<i; j++) if ( abs(a[i]+a[j])==k && (j!=i)) d++;}


cout<<d;

return 0;

You might also like