Ім'я файлу: Olloyarov Tohir lab2.docx
Розширення: docx
Розмір: 859кб.
Дата: 30.03.2023
скачати

МИНИСТЕРСТВО РАЗВИТИЯ ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ И РАЗВИТИЯ КОММУНИКАЦИИ РЕСПУБЛИКИ УЗБЕКИСТАН

УРГЕНЧЕСКИЙ ФИЛИАЛ ТАШКЕНТСКОГО УНИВЕРСИТЕТА ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ ИМЕНИ МУХАММАДА АЛЬ-ХОРАЗМИЙ


Лабораторная работа№2

Проектирование алгоритмов

Группа: 962-20 (заочная)

Сдал(а): Оллоёров Тохир

Принял:

1-Topshiriq


Sizga bir o’lchmli.butun sonlardan iborat massiv berilgan. Sizning vazifangiz bumassiv elemntlarini modullari jihatdan kamaymaslik tartibida saralaydigandastur tuzish. Agar modul jihatdan teng musbat va manfiy sonlar mavjud bo’lsamanfiy son oldinroq joylashtirilsin.



Kiruvchi ma’lumotlar: Birinchi qatorda bitta butun son n (1≤n≤200). Ikkinchiqatorda n ta butun son −massiv elementlari  bitta probel bilan ajratilib berilgan.Massiv elementlari qiymati modul jihatdan 10dan oshmaydi.

Chiquvchi ma’lumotlar: Saralangan massiv elementlarini bitta qatorda bittaprobel bilan ajratib chiqaring.



Kiruvchi ma’lumotlar

Chiquvchi ma’lumotlar

1

6

9 8 -9 2 -4 3

2 3 -4 8 -9 9

2

5

2 -2 -2 2 0

0 -2 -2 2 2





#include

using namespace std;

double func(int a[], int b[], int n)

{

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

for (int j = 0; j < i; j++)

{

if (a[j] > a[j+1])

{

swap(a[j],a[j+1]);

swap(b[j],b[j+1]);

}

if(a[j]==a[j+1] and b[j+1]==0)

swap(b[j],b[j+1]);

}

}

int main()

{

int n; cin>>n;

int a[n],b[n];

for(int i=0; i
{

cin>>a[i];

if(a[i]<0)

{ b[i]=0; a[i]*=-1; }

else

b[i]=1;

}

func(a,b,n);

cout<<"\nNatija...\n";

for(int i=0; i
{

if(b[i]==0)

a[i]*=-1;

}

for(int i=0; i
{

cout<
}

}





5-Topshiriq

On programming contests each team consists of three people and has a name. Write a program that for a team name and surnames of the participants, the full name of the team builds.

Full name of the team consists of a short list of team names and the names of its members. Names of the participants in the list must be sorted alphabetically and separated by exactly one comma and space and must be brackets on both side(see examples).

Input

 The Input contains exactly 4 lines. The first line contains the name of team. Each of the following three lines contains the surname of one of the teammates. The Lengths of the lines do not exceed 50 symbols.

Output                                        

Output must contain exactly one line, containing full team name.

Samples     



Input

Output

1

Team#6

Yusupova

Yuldoshova

Jumaboeva

Team#6(Jumaboeva, Yuldoshova, Yusupova)

2

TUIT Urgench Branch#4

Odilov

Xusinov

Axmedov

TUIT Urgench Branch#4(Axmedov, Odilov,Xusinov)

#include

using namespace std;

int main()

{

string s;

getline(cin, s);

string a[3];

for (int i=0; i<3; i++) cin>>a[i];

for (int i=0; i<3; i++)

for (int j=0; j<3; j++)

if (a[i] < a[j]){

swap(a[i], a[j]);

}

cout << s << "(";

for (int i=0; i<3; i++)

if (i != 2) cout << a[i] << ", ";

else cout << a[i];

cout << ")" << endl;

}



6-Topshiriq

The array is sorted with selection sort in ascending order. How many times does the first element in initial array change its position?

  Input

The first line contains the number of elements in array n (1 ≤ n ≤ 1000). The second line contains the elements of array. It is known that all elements in array are different and not greater than 109 by absolute value.

  Output

Print the number of movements of the first element.

  Samples



Input

Output

1

3

1 3 2

0

2

2

2 1

1

3

4

4 1 5 3

3

#include

using namespace std;

int main() {

int n; cin>>n;

int a[n]; int s=0;

for (int i = 0; i < n; i++) cin>>a[i];

int fst = a[0];

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

int minPos = i;

for (int j = i+1; j < n; j++)

if (a[j] < a[minPos])

{

if (fst == a[i] || fst == a[j]) s++;

minPos = j;

}

swap(a[i], a[minPos]);

}

cout << s << endl;
}







10-Topshiriq

N ta son berilgan. Ulardan shunday uchtasini tanlash kerakki, ularning ko’paytmasi maksimal bo’lsin.
Kiruvchi ma’lumotlar

Birinchi qatorda N butun soni beriladi(3 ≤ n ≤ 1000). Ikkinchi qatorda N ta son bitta probel bilan ajratilgan holda beriladi. Ularning qiymatlari butun va modul jihatidan 106 dan oshmaydi.

Chiquvchi ma’lumotlar

Bitta butun sonni – maksimal ko’paytmaning qiymatini chiqaring.

Misollar




Kiruvchi ma’lumotlar

Chiquvchi ma’lumotlar

1

5

5 6 -9 4 3

120

2

3

-5 -7 -2

-70

#include

using namespace std;

int main()

{

int n;

cin >> n;

int a[n];

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

cin>>a[i];

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

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

if (a[j] < a[j+1]) {

swap(a[j], a[j+1]);

}

}

}

cout << a[0]*a[1]*a[2];

}




скачати

© Усі права захищені
написати до нас