Advertisement
huutho_96

bt3

Apr 24th, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define MAX 1024
  4. struct ThongTin
  5. {
  6. int ngay, thang, nam;
  7. char sdt[15];
  8. };
  9. void Nhap(ThongTin tt[], int n)
  10. {
  11. for (int i = 0; i < n; i++)
  12. {
  13. scanf("%d %d %d %s", &tt[i].ngay, &tt[i].thang, &tt[i].nam, &tt[i].sdt);
  14. }
  15. }
  16. void Xuat(ThongTin tt[], int n)
  17. {
  18. for (int i = 0; i < n; i++)
  19. {
  20. cout << tt[i].ngay << " " << tt[i].thang << " " << tt[i].nam << " " << tt[i].sdt << endl;
  21. }
  22. }
  23. void Swap(int &a, int &b)
  24. {
  25. int temp = a;
  26. a = b;
  27. b = temp;
  28. }
  29. void Swap(ThongTin &a, ThongTin &b)
  30. {
  31. ThongTin temp = a;
  32. a = b;
  33. b = temp;
  34. }
  35. void QuickSort(ThongTin tt[], int a[], int left, int right) {
  36. int i, j, x;
  37. x = a[(left + right) / 2];
  38. i = left; j = right;
  39. do{
  40. while (a[i] < x) i++;
  41. while (a[j] > x) j--;
  42. if (i <= j)
  43. {
  44. Swap(a[i], a[j]);
  45. Swap(tt[i], tt[j]);
  46. i++;
  47. j--;
  48. }
  49. } while (i <= j);
  50. if (left<j)
  51. QuickSort(tt, a, left, j);
  52. if (i<right)
  53. QuickSort(tt, a, i, right);
  54. }
  55. void TinhNgaySinh(ThongTin tt[], int a[], int n)
  56. {
  57. for (int i = 0; i < n; i++)
  58. {
  59. a[i] = (tt[i].nam * 100 + tt[i].thang) * tt[i].ngay;
  60. }
  61. }
  62. void main()
  63. {
  64. int n;
  65. ThongTin tt[MAX];
  66. int a[MAX];
  67. cin >> n;
  68. Nhap(tt, n);
  69. TinhNgaySinh(tt, a, n);
  70. QuickSort(tt, a, 0, n - 1);
  71. Xuat(tt, n);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement