fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define FOr(i, a, b) for (int i = a; i < b; i++)
  4. #define FOR(i, a, b) for (int i = a; i <= b; i++)
  5. #define FOrd(i, a, b) for (int i = a; i > b; i--)
  6. #define FORD(i, a, b) for (int i = a; i >= b; i--)
  7. #define faster() \
  8. ios_base ::sync_with_stdio(0); \
  9. cin.tie(NULL); \
  10. cout.tie(NULL);
  11. using namespace std;
  12. struct NhanVien
  13. {
  14. string ma;
  15. string ten, gt, ns, dc, mst, hd;
  16. };
  17. int j = 1;
  18. void nhap(NhanVien &a)
  19. {
  20. string tmp = to_string(j);
  21. a.ma = string(5 - tmp.size(), '0') + tmp;
  22. j++;
  23. getline(cin >> ws, a.ten);
  24. cin >> a.gt >> a.ns;
  25. cin.ignore();
  26. getline(cin >> ws, a.dc);
  27. cin >> a.mst >> a.hd;
  28. }
  29. void inds(NhanVien ds[], int N)
  30. {
  31. FOr(i, 0, N)
  32. {
  33. cout << ds[i].ma << " " << ds[i].ten << " " << ds[i].gt << " " << ds[i].ns << " ";
  34. cout << ds[i].dc << " " << ds[i].mst << " " << ds[i].hd << endl;
  35. }
  36. }
  37. bool cmp(NhanVien &a, NhanVien &b)
  38. {
  39. int year1 = stoi(a.ns.substr(6, 4));
  40. int year2 = stoi(b.ns.substr(6, 4));
  41. if (year1 != year2)
  42. {
  43. return year1 < year2;
  44. }
  45. else
  46. {
  47. int month1 = stoi(a.ns.substr(3, 2));
  48. int month2 = stoi(b.ns.substr(3, 2));
  49. if (month1 != month2)
  50. {
  51. return month1 < month2;
  52. }
  53. else
  54. {
  55. int day1 = stoi(a.ns.substr(0, 2));
  56. int day2 = stoi(b.ns.substr(0, 2));
  57. return day1 < day2;
  58. }
  59. }
  60. }
  61. void sapxep(NhanVien ds[], int n)
  62. {
  63. sort(ds, ds + n, cmp);
  64. }
  65. int main()
  66. {
  67. struct NhanVien ds[50];
  68. int N, i;
  69. cin >> N;
  70. for (i = 0; i < N; i++)
  71. nhap(ds[i]);
  72. sapxep(ds, N);
  73. inds(ds, N);
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty