fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Data{
  5. string Name, Sdt, Date;
  6. };
  7.  
  8. bool check(string s){
  9. for(auto x : s){
  10. if(!isdigit(x)){
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16.  
  17. string ChuanHoa(string s, string &tmp){
  18. stringstream ss(s);
  19. string token;
  20. vector<string> vt;
  21. while(ss >> token){
  22. vt.push_back(token);
  23. }
  24. string x = "";
  25. for(int i = 0; i < vt.size() - 1; i++){
  26. x += vt[i];
  27. if(i != vt.size() - 2){
  28. x += " ";
  29. }
  30. }
  31. tmp = x;
  32. return vt[vt.size() - 1];
  33. }
  34.  
  35. bool cmp(Data x, Data y){
  36. string hx, hy, kx, ky;
  37. hx = ChuanHoa(x.Name, kx);
  38. hy = ChuanHoa(y.Name, ky);
  39. if(hx == hy){
  40. return kx < ky;
  41. }
  42. return hx < hy;
  43. }
  44.  
  45. int main(){
  46. ifstream in; in.open("SOTAY.txt");
  47. ofstream out; out.open("DIENTHOAI.txt");
  48. Data a[1000];
  49. string s;
  50. string tmp;
  51. int n = 0;
  52. bool mark1 = true, mark2 = true;
  53. while(getline(in, s)){
  54. if(s.find("/") != string::npos){
  55. tmp = s;
  56. }
  57. else if(check(s) == false){
  58. a[n].Name = s;
  59. mark1 = false;
  60. }
  61. else{
  62. a[n].Sdt = s;
  63. mark2 = false;
  64. }
  65. if(mark1 == false && mark2 == false){
  66. a[n].Date = tmp;
  67. ++n;
  68. mark1 = true; mark2 = true;
  69. }
  70. }
  71. sort(a, a + n, cmp);
  72. for(int i = 0; i < n; i++){
  73. out << a[i].Name << ": " << a[i].Sdt << " " << a[i].Date << endl;
  74. }
  75. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty