X va Y ikkita to’plam(Set) berilgan. X va Y to‘plamlarining toq qiymatlilaridan Z to‘plamni tashkil etuvchi dastur tuzing
#include
#include
using namespace std;
int main() {
set X = {1, 2, 3, 4, 5};
set Y = {3, 4, 5, 6, 7};
set Z;
for (auto it = X.begin(); it != X.end(); ++it) {
if (*it % 2 != 0) { Z.insert(*it);}}
for (auto it = Y.begin(); it != Y.end(); ++it) {
if (*it % 2 != 0) { Z.insert(*it);}}
cout << "Z to'plami: ";
for (auto it = Z.begin(); it != Z.end(); ++it) {
cout << *it << " "; }
cout << endl;
return 0;}
R to‘plam (multiset) berilgan. D to‘plamga uning maksimal va minimal qiymatlaridan tashqari bo‘lgan qiymatlarini yozadigan dastur tuzing.
#include
#include
using namespace std;
int main() {
multiset s = {1, 3, 2, 4, 2, 5, 1};
int max_val = *s.rbegin(); // maximal qiymat
int min_val = *s.begin(); // minimal qiymat
s.erase(max_val);
s.erase(min_val);
for (int x : s) {
cout << x << " ";
}
cout << endl;
return 0;
}
|
X to‘plami(multiset) ning o‘rta arifmetik va o‘rta geometrik qiymatlarini aniqlang.
#include
#include
using namespace std;
int main() {
multiset s = {1, 3, 2, 4, 2, 5, 1};
int sum = 0;
double mean_arith = 0.0; // o'rta arifmetik
double mean_geom = 1.0; // o'rta geometrik
int cnt = 0; // tushunmovchilikni oldini olish uchun
for (int x : s) {
sum += x;
mean_geom *= x; cnt++;}
mean_arith = (double)sum / cnt;
mean_geom = pow(mean_geom, 1.0/cnt);
cout << "O'rta arifmetik qiymati: " << mean_arith << endl;
cout << "O'rta geometrik qiymati: " << mean_geom << endl;
return 0;
}
|
X to‘plami(multiset)ning o‘rta arifmetik qiymatidan katta va o‘rta geometrik qiymatdan kichik bo‘lgan qiymatlar sonini aniqlovchi dastur tuzing.
#include
#include
using namespace std;
int main() { multiset s = {1, 3, 2, 4, 2, 5, 1};
double mean_arith = 0.0; // o'rta arifmetik
double mean_geom = 1.0; // o'rta geometrik
int cnt = 0; // tushunmovchilikni oldini olish uchun
int cnt_max_arith = 0; // katta bo'lgan qiymatlar soni
int cnt_min_geom= 0; // kichik bo'lgan qiymatlar soni
for (int x : s) { mean_arith += x;
mean_geom *= x; cnt++;} mean_arith /= cnt;
mean_geom = pow(mean_geom, 1.0/cnt);
for (int x : s) { if (x > mean_arith) {cnt_max_arith++;} if (x < mean_geom) {cnt_min_geom++;}} cout << "Katta bo'lgan qiymatlar soni: " << cnt_max_arith << endl;
cout << "Kichik bo'lgan qiymatlar soni: " << cnt_min_geom << endl;
return 0;}
X to‘plamning tub qiymatlaridan D to‘plamni tashkil eting
#include
#include
using namespace std;
// tub sonmi tekshirish funksiyasi
bool is_prime(int n) {
if (n < 2) { return false;}
for (int i = 2; i*i <= n; i++) {
if (n % i == 0) {
return false;} } return true;}
int main() {
multiset x = {1, 3, 2, 4, 2, 5, 1};
set d;
for (int val : x) {
if (is_prime(val)) {
d.insert(val);} }
for (int val : d) {
cout << val << " ";}
cout << endl;
return 0;}
|
X to‘plam berilgan. X to‘plam qiymatlarini kamayib borish tartibida joylang. Agar bir xil qiymatlilari bo‘lsa, ulardan bittasini qoldirib, qolganlarini o‘chiradigan dastur tuzing.
#include
#include
using namespace std;
int main() {
multiset s = {1, 3, 2, 4, 2, 5, 1};
// to'plamni kamayib borish tartibida joylash
set unique_vals; // bir xil qiymatlarni saqlash uchun
for (int x : s) {
unique_vals.insert(x);
}
for (int x : unique_vals) {
cout << x << " ";
}
cout << endl;
return 0;}
X to‘plamning bir xil qiymatlilarini o‘chiruvchi dastur tuzing.
#include
#include
using namespace std;
int main() {
multiset s = {1, 3, 2, 4, 2, 5, 1};
set unique_vals; // bir xil qiymatlarni saqlash uchun
for (int x : s) {
unique_vals.insert(x);}
s.clear(); // asosiy to'plamni tozalaymiz
for (int x : unique_vals) {
int count = s.count(x);
if (count == 1) { s.insert(x);}}
for (int x : s) {
cout << x << " ";}
cout << endl;
return 0;}
|
|
Do'stlaringiz bilan baham: |