Cấu Trúc Dữ Liệu - Tuần 1
Link Down: Click See
Bài Tập 1
#include<iostream> using namespace std; void inPut_Arr(int a[], int n){ for(int i=0; i<n; i++){ cout << "Nhap Phan Tu Thu " << i+1 << ": "; cin >> a[i]; } } int search_TuyenTinh(int a[], int n, int x){ for(int i=0; i<n; i++){ if(a[i] == x){ return i+1; break; } } return -1; } bool search_Binary(int a[], int n, int x){ int left_Arr = 0, right_Arr = n-1, mid_Arr; do{ mid_Arr = (left_Arr + right_Arr) / 2; if(mid_Arr == x) return true; else if(x < mid_Arr) right_Arr = mid_Arr - 1; else left_Arr = mid_Arr + 1; }while(left_Arr <= right_Arr); return false; } int main(){ cout << "===== Thuat Toan Tuyen Tinh =====\n\n"; cout << "_____ Bai Tap 1 _____\n"; cout << "Nhap So Luong Phan Tu: "; int n; cin >> n; int a[n]; inPut_Arr(a,n); cout << "\nNhap X: "; int x; cin >> x; int b = search_TuyenTinh(a,n,x); if(b == -1) cout << "Khong Tim Thay " << x; else cout << "Tim Thay " << x << " Tai Vi Tri " << b; cout << "\n\n _____ Tim Kiem Nhi Phan _____\n"; cout << "\nNhap X: "; int c; cin >> c; if(search_Binary(a,n,c) == true) cout << "Tim Thay " << c << " Trong Mang"; else cout << "Khong Tim Thay " << c << " Trong Mang"; return 0; }
#include<iostream> using namespace std; void inPut_Arr(int a[], int n){ for(int i=0; i<n; i++){ cout << "Nhap Phan Tu Thu " << i+1 << ": "; cin >> a[i]; } } void search_Max_Min(int a[], int n){ int max, min; max = min = a[0]; for(int i=1; i<n; i++) if(a[i] > max) max = a[i]; for(int i=1; i<n; i++) if(a[i] < min) min = a[i]; cout << "Max = " << max << " | Min = " << min ; } bool KiemTraSoNguyenTo(int a){ if(a < 2) return false; else for(int i=2; i<=a/2; i++) if(a % i == 0) return false; return true; } void LietKeSoNguyenTo(int a[], int n){ cout << "Day So Nguyen To: "; for(int i=0; i<n; i++) if(KiemTraSoNguyenTo(a[i]) == true) cout << a[i] << " "; } int main(){ cout << "Nhap So Luong Phan Tu: "; int n; cin >> n; int a[n]; inPut_Arr(a,n); search_Max_Min(a,n); LietKeSoNguyenTo(a,n); return 0; } continue...
https://www.phutungmercedes.net/gara-sua-chua-xe-mercedes-tai-ha-noi/
Trả lờiXóa