fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. struct people{
  6. string bo, con;
  7. int chenhlech; int tuoi;
  8. };
  9.  
  10.  
  11. int n;
  12. people a[105];
  13.  
  14. void solve(string name, int age)
  15. {
  16. for(int i = 0; i < n; i++)
  17. {
  18. if(name == a[i].bo)
  19. {
  20. if(name == "Ted")
  21. {
  22. a[i].tuoi = 100 - a[i].chenhlech;
  23. solve(a[i].con, a[i].tuoi);
  24. }
  25. else
  26. {
  27. a[i].tuoi = age - a[i].chenhlech;
  28. solve(a[i].con, a[i].tuoi);
  29. }
  30. }
  31. }
  32. }
  33.  
  34. bool cmp(people x, people y)
  35. {
  36. if(x.tuoi != y.tuoi)
  37. {
  38. return x.tuoi > y.tuoi;
  39. }
  40. else
  41. {
  42. return x.con < y.con;
  43. }
  44. }
  45.  
  46.  
  47. int main()
  48. {
  49. cin >> n;
  50. for(int i = 0; i < n; i++)
  51. {
  52. cin.ignore();
  53. cin >> a[i].bo >> a[i].con;
  54. cin >> a[i].chenhlech;
  55. }
  56. solve("Ted", 100);
  57. sort(a,a+n,cmp);
  58. for(int i = 0; i < n; i++)
  59. {
  60. cout << a[i].con << ' ' << a[i].tuoi << "\n";
  61. }
  62. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty