Untitled
// bai 1 #include <iostream> #include <math.h> using namespace std; int main() { int n; cout << "Nhap so luong phan tu\n"; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { cout << a[i] * 1ll * a[i + 1] << " "; } } // bai 2 #include <iostream> #define ll long long #define MOD 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n], b[n]; // mang b la mang luu so luong phan tu moi for (int &i : a) cin >> i; int res = -1e9, cnt = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] > res) { res = a[i]; b[cnt++] = res; } } for (int i = cnt - 1; i >= 0; i--) cout << b[i] << " "; } // bai 3 #include <bits/stdc++.h> // thu vien tong hop(khong phai thu vien chuan cua c++) #define ll long long #define MOD 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int demChan = 0, demLe = 0; long long tongChan = 0, tongLe = 0; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { ++demChan; tongChan += a[i]; } else { ++demLe; tongLe += a[i]; } } cout << "\nSo luong so chan\n" << demChan; cout << "\nSo luong so le\n" << demLe; cout << "\nTong so chan\n" << tongChan; cout << "\nTong so le\n" << tongLe; } // bai 4 #include <bits/stdc++.h> // thu vien tong hop(khong phai thu vien chuan cua c++) #define ll long long #define MOD 1000000007 using namespace std; int cnt[1000007]; // mang danh dau int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; // danh dau cac gia tri trong mang a } for (int i = 0; i < n; i++) { if (cnt[a[i]] != 0) { cout << a[i] << " " << cnt[a[i]] << endl; cnt[a[i]] = 0; } } } // bai 5 #include <bits/stdc++.h> // thu vien tong hop(khong phai thu vien chuan cua c++) #define ll long long #define MOD 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (a[i] == 79) { for (int j = i; j < n - 1; j++) { a[j] = a[j + 1]; } --n; --i; } } if (n == 0) { cout << "EMPTY\n"; } else { for (int i = 0; i < n; i++) { cout << a[i] << " "; } } }
Leave a Comment