//Navbat o‘rtasidagi element o‘chirib tashlansin.Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin.
#include
#include
using namespace std;
int main() {
vector nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int size = nums.size();
// Navbat elementlari sonini hisoblash
int mid = (size + 1) / 2;
// Navbat elementlari soni toq yoki juft ekanligini tekshirish va mos holga o'chirish
if (size % 2 == 1) {
nums.erase(nums.begin() + mid - 1);
}
else {
nums.erase(nums.begin() + mid - 1);
nums.erase(nums.begin() + mid);
}
// Vectorni chiqarish
for (int i = 0; i < nums.size(); i++) {
cout << nums[i] << " ";
}
cout << endl;
return 0;
}
Do'stlaringiz bilan baham: |