Rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalar universiteti


Download 16.59 Kb.
Sana29.11.2021
Hajmi16.59 Kb.
#470731
Bog'liq
Il
4-практика№4, Algebra va matematik analiz fanidan lug at (R.Yarqulov, M.Barakayeva), Маъмуралиев Авазбек 1, Мустакил иш, Мустакил иш, Амалиёт-15, fulltext, sss, civil proj advt, civil proj advt, problem, integral tenglamalarni yechish metodlari — копия, VLSI Implementation of Cellular Neural N, Sayt nomi, Sayt nomi

O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMUNIKATSIYALARNI

RIVOJLANTIRISH VAZIRLIGI

MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT

TEXNOLOGIYALAR UNIVERSITETI

MTA FANIDAN 2-LABARATORIYA ISHI


Bajardi: Mag’zimov Ilhomjon
Tekshirdi:Mo’minov S.

Toshkent-2021



10-variant

10.Boshiga qo‘yish usulidan foydalanib ro‘yhatda 11 ga butun bo‘linuvchi eng katta sonni toping (agar bunday sonlar ko‘p bo‘lsa, u holda ularning eng kattasini toping; agar bunday son mavjud bo‘lmasa – shunga mos ma’lumot chiqaring

// C++ implementation of above approach

#include

using namespace std;

#define ll long long

// Function to find the largest

// integer with the given set

int findLargest(int n, vector& v)

{

int flag = 0;



ll sum = 0;

// find sum of all the digits

// look if any 0 is present or not

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

if (v[i] == 0)

flag = 1;

sum += v[i];

}

// if 0 is not present, the resultant number



// won't be divisible by 5

if (!flag)

cout << "Not possible" << endl;

else {


// sort all the elements in a non-decreasing manner

sort(v.begin(), v.end(), greater());

// if there is just one element 0

if (v[0] == 0) {

cout << "0" << endl;

return 0;

}

else {


int flag = 0;

// find the remainder of the sum

// of digits when divided by 3

int y = sum % 3;

// there can a remainder as 1 or 2

if (y != 0) {

// traverse from the end of the digits

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

// first element which has the same remainder

// remove it

if (v[i] % 3 == y) {

v.erase(v.begin() + i);

flag = 1;

break;


}

}

// if there is no element which



// has a same remainder as y

if (flag == 0) {

// subtract it by 3 ( could be one or two)

y = 3 - y;

int cnt = 0;

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

// delete two minimal digits

// which has a remainder as y

if (v[i] % 3 == y) {

v.erase(v.begin() + i);

cnt++;

if (cnt >= 2)

break;

}

}



}

}

if (*v.begin() == 0)



cout << "0" << endl;

// print all the digits as a single integer

else

for (int i : v) {



cout << i;

}

}



}

}

// Driver code



int main()

{

// initialize the number of set of digits



int n = 11;

// initialize all the set of digits in a vector

vector v{ 3, 9, 9, 6, 4, 3, 6, 4, 9, 6, 0 };

findLargest(n, v);

return 0;

}

Natija:




Download 16.59 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2022
ma'muriyatiga murojaat qiling