Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define MAX 1024
- struct ThongTin
- {
- int ngay, thang, nam;
- char sdt[15];
- };
- void Nhap(ThongTin tt[], int n)
- {
- for (int i = 0; i < n; i++)
- {
- scanf("%d %d %d %s", &tt[i].ngay, &tt[i].thang, &tt[i].nam, &tt[i].sdt);
- }
- }
- void Xuat(ThongTin tt[], int n)
- {
- for (int i = 0; i < n; i++)
- {
- cout << tt[i].ngay << " " << tt[i].thang << " " << tt[i].nam << " " << tt[i].sdt << endl;
- }
- }
- void Swap(int &a, int &b)
- {
- int temp = a;
- a = b;
- b = temp;
- }
- void Swap(ThongTin &a, ThongTin &b)
- {
- ThongTin temp = a;
- a = b;
- b = temp;
- }
- void QuickSort(ThongTin tt[], int a[], int left, int right) {
- int i, j, x;
- x = a[(left + right) / 2];
- i = left; j = right;
- do{
- while (a[i] < x) i++;
- while (a[j] > x) j--;
- if (i <= j)
- {
- Swap(a[i], a[j]);
- Swap(tt[i], tt[j]);
- i++;
- j--;
- }
- } while (i <= j);
- if (left<j)
- QuickSort(tt, a, left, j);
- if (i<right)
- QuickSort(tt, a, i, right);
- }
- void TinhNgaySinh(ThongTin tt[], int a[], int n)
- {
- for (int i = 0; i < n; i++)
- {
- a[i] = (tt[i].nam * 100 + tt[i].thang) * tt[i].ngay;
- }
- }
- void main()
- {
- int n;
- ThongTin tt[MAX];
- int a[MAX];
- cin >> n;
- Nhap(tt, n);
- TinhNgaySinh(tt, a, n);
- QuickSort(tt, a, 0, n - 1);
- Xuat(tt, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement