Amaliy ish Bajardi: 012-1-(512-22)-guruh talabasi Raxmatullayeva Ruxshona O’qituvchi: Babajanov Mo’min Rajabovich 2-laboratoriya ishi 1-vazifa
Download 1.67 Mb.
|
1 2
Bog'liq1680194352 (1)
2-VAZIFA
14.Ikkita ixtiyoriy vectorni bir xil ekanligini aniqlovchi va bir xil bo‘lsa bittasini o‘chiruvchi funksiyalar yarating. #include #include using namespace std; template void printVector(vector for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << endl; } template bool isSameVector(vector if (v1.size() != v2.size()) { return false; } for (int i = 0; i < v1.size(); i++) { if (v1[i] != v2[i]) { return false; } } return true; } template void removeDuplicates(vector for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { if (v[i] == v[j]) { v.erase(v.begin() + j); j--; } } } } int main() { vector vector vector cout << "v1: "; printVector(v1); cout << "v2: "; printVector(v2); cout << "v3: "; printVector(v3); if (isSameVector(v1, v2)) { cout << "v1 va v2 vectorlar birxil" << endl; } else { cout << "v1 and v2 vectorlar birxil emas" << endl; } removeDuplicates(v1); cout << "v3 vector: "; printVector(v1); return 0; } 3-VAZIFA 14.String turidagi To‘plam berilgan. Undagi elementlarni char turidagi A massivga joylashtirib, polindrom so‘zlar sonini aniqlovchi dastur tuzing. #include #include #include using namespace std; bool isPalindrome(char A[]) { int len = strlen(A); for(int i=0; i if(A[i] != A[len-i-1]) { return false; } } return true; } int main() { string s; cout << "Enter a string: "; getline(cin, s); int count = 0; for(int i=0; i char A[s.length()-i+1]; int k = 0; for(int j=i; j A[k++] = s[j]; A[k] = '\0'; if(isPalindrome(A)) { count++; } } } cout << "Number of palindromic substrings: " << count << endl; return 0; } 4-vazifa 14.X to‘plam berilgan. Uning qiymatlari oldiga 3 ni joylashtirib(masalan: 4 bo‘lsa, 34. 5 bo‘lsa 35), ularni max va min larini aniqlovchi dastur tuzing. #include #include using namespace std; int main() { forward_list int max_num = *mylist.begin(); // Initializing max_num to the first element of the list int min_num = *mylist.begin(); // Initializing min_num to the first element of the list // Looping through the list to find the max and min elements for (auto it = mylist.begin(); it != mylist.end(); ++it) { if (*it > max_num) { max_num = *it; } if (*it < min_num) { min_num = *it; } } // Adding 3 to the max and min numbers max_num += 3; min_num += 3; // Printing the new max and min numbers cout << "Max number: " << max_num << endl; cout << "Min number: " << min_num << endl; return 0; } Download 1.67 Mb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling