MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT
TEXNOLOGIYALARI UNIVERSITETI
1- AMALIY ISH
Talaba: Mo’minov Og’abek
Guruh: SWD008-2
Tekshirdi: Djangazova Kumriniso
1 – topshiriq.
Ismni chiqarish.
#include <iostream>
using namespace std;
int main() {
int n ;
cout<<"n ni kititng:";
cin>>n;
cout << "\n\n";
char arr4[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 || i == n - 1 || i == n / 2 || (j == n - 1 && i > n / 2) || (j == 0 && i < n / 2)) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == n / 2 || i + j == n / 2 || (i < n / 2 && j > n / 2 && i == j - n / 2) || (i > n / 2 && (j ==
0 || j == n - 1))) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j == n / 2 || (i == 0 && (j == (n / 2 - 1) || j == (n / 2 + 1))) ||
(i == n - 1 && (j == (n / 2) - 1 || j == n / 2 + 1))) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j == 0 || j == n - 1 && (i != 0 && i != n - 1) || i == n - 1 && (j != n - 1) ||
i == 0 && (j != n - 1)) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((i == 0 && (j != 0 && j != n - 1)) || i == n - 1 && (j != 0 && j != n - 1) ||
j == n - 1 && (i != 0 && i != n - 1) || j == 0 && (i != 0 && i != n - 1)) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j == 0 || j == n - 1 && i > 0 && i < n / 2 || i == n / 2 && (j != n - 1) || i == 0 && (j !=
n - 1) ||
(i > n / 2 && i == j)) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j == n / 2 || (i == 0 && (j == (n / 2 - 1) || j == (n / 2 + 1))) ||
(i == n - 1 && (j == (n / 2) - 1 || j == n / 2 + 1))) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 && j < n - 1 || j == 0 || i == n / 2 && j < n / 2 + 1) {
arr4[i][j] = '*';
} else {
arr4[i][j] = ' ';
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << " " << arr4[i][j] << " ";
}
cout << endl;
}
cout << endl;
return 0;
}
2-topshiriq
Quick sort
#include <iostream>
using namespace std;
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] <= pivot) {
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
int pi = i + 1;
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
int main() {
int arr[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(arr) / sizeof(arr[0]);
quickSort(arr, 0, n - 1);
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
return 0;
}
NAIV qidiruv
#include <iostream>
using namespace std;
void naiveSearch(string txt, string pat) {
int n = txt.length();
int m = pat.length();
for (int i = 0; i <= n - m; i++) {
int j;
for (j = 0; j < m; j++)
if (txt[i + j] != pat[j])
break;
if (j == m)
cout << "Kichik satr " << i << "-indeksda topildi\n";
}
}
int main() {
string txt = "hello, this is a simple example";
string pat = "simple";
naiveSearch(txt, pat);
return 0;
}