Texnologiyalari va kommunikatsiyalarini rivojlantirish vazirligi



Yüklə 32,69 Kb.
səhifə1/3
tarix24.12.2023
ölçüsü32,69 Kb.
#160377
  1   2   3
4-5-6 paradigma


O’ZBEKISTON RESPUBLIKASI AXBOROT
TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI
RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL XORAZMIY NOMIDAGI
TOSHKENT AXBOROT
TEXNOLOGIYALARI UNIVERSITETI
DASTURLAS USLUBLARI VA PARADIGMALAR (AMALIY) FANIDAN



Masalalar:
Task 4. Karobka va sharlar.
Task 5. Katta va kichiklar uchun bilet narxi.
Task 6. Natural sonlarni ikkilik sanoq ko’rinishiga o’tkazib, ular orasida 1 ta nolga ega sonlar.

4-masala
c++ da dastur kodi:
#include
#include
#include
#include

#define debug true

using namespace std;

int main()


{
vector vec;
int N, M, x;
cin >> N >> M;

for (int i = 0; i < M; i++)
{
cin >> x;
vec.push_back(x);
}

copy(vec.begin(), vec.end(), ostream_iterator(cout, " "));
cout << endl;

int K = 0;

while (!all_of(vec.begin(), vec.end(), [](int x){ if (x) return true; }))
{

auto nol = vec.begin();

while (nol != vec.end() && *nol != 0) nol++;

auto it = vec.begin();

int i = -1;
int k = M + 2;

while (it != vec.end())
{
if (it != nol && *it > 1 && k > min(((it - nol) + M) % M, abs(it - nol)))
{
k = min(((it - nol) + M) % M, abs(it - nol));
i = it - vec.begin();
}
it++;
}

K += k;
*nol = *nol + 1;
vec[i]--;

if (debug)
{
cout << hue::green << i + 1 << " " << nol - vec.begin() + 1 << " " << k << hue::reset << endl;
copy(vec.begin(), vec.end(), ostream_iterator(cout, " "));
int p = nol - vec.begin();

cout << endl;


}
}
cout << "natija : " << K << endl;
return 0;
}



Yüklə 32,69 Kb.

Dostları ilə paylaş:
  1   2   3




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə