МИНИСТЕРСТВО РАЗВИТИЯ ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ И РАЗВИТИЯ КОММУНИКАЦИИ РЕСПУБЛИКИ УЗБЕКИСТАНУРГЕНЧЕСКИЙ ФИЛИАЛ ТАШКЕНТСКОГО УНИВЕРСИТЕТА ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ ИМЕНИ МУХАММАДА АЛЬ-ХОРАЗМИЙЛабораторная работа№2 Проектирование алгоритмов Группа: 962-20 (заочная) Сдал(а): Оллоёров Тохир Принял: 1-Topshiriq
#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
#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
#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
#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]; } |