fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. struct Doctors{
  5. string first_name;
  6. string last_name;
  7. string spec;
  8. int years;
  9. };
  10. void read_doc(Doctors &x);
  11.  
  12. void write_doc(const Doctors &x);
  13.  
  14. void read_doctor(Doctors*x,int n);
  15.  
  16. void write_doctor(Doctors*x,int n);
  17.  
  18. bool comp(Doctors a, Doctors b);
  19. bool comp1(Doctors a,Doctors b);
  20. int summ(Doctors*x,int n);
  21. int main() {
  22. int n;
  23. cin>>n;
  24. Doctors *x=new Doctors[n];
  25. // for(int i=0;i<n;++i){
  26. // read_doc(x[i]);
  27. // }
  28. // for(int i=0;i<n;++i){
  29. // write_doc(x[i]);
  30. // }
  31. read_doctor(x,n);
  32. write_doctor(x,n);
  33. cout<<"------------"<<endl;
  34. sort(x,x+n,comp);
  35. write_doctor(x,n);
  36. cout<<"------------"<<endl;
  37. sort(x,x+n,comp1);
  38. write_doc(x[0]);
  39. cout<<endl<<"-------------"<<endl;
  40.  
  41. cout<<summ(x,n);
  42. delete []x;
  43. return 0;
  44. }
  45. int summ(Doctors*x,int n){
  46. double sum=0;
  47. for(int i=0;i<n;i++){
  48. sum += x[i].years;
  49. }
  50. return sum;
  51. }
  52.  
  53. bool comp(Doctors a, Doctors b){
  54. return a.spec<b.spec;
  55. }
  56. bool comp1(Doctors a, Doctors b){
  57. return a.years>b.years;
  58. }
  59.  
  60. void read_doctor(Doctors*x,int n){
  61. for(int i=0;i<n;++i){
  62. cin>>x[i].first_name;
  63. cin>>x[i].last_name;
  64. cin>>x[i].spec;
  65. cin>>x[i].years;
  66. }
  67. }
  68. void write_doctor(Doctors*x,int n){
  69. for(int i=0;i<n;++i){
  70. cout<<x[i].first_name<<" ";
  71. cout<<x[i].last_name<<" ";
  72. cout<<x[i].spec<<" ";
  73. cout<<x[i].years<<endl;
  74. }
  75. }
  76. void read_doc(Doctors &x){
  77. cin>>x.first_name;
  78. cin>>x.last_name;
  79. cin>>x.spec;
  80. cin>>x.years;
  81. }
  82. void write_doc(const Doctors &x){
  83. cout<<x.first_name<<" ";
  84. cout<<x.last_name<<" ";
  85. cout<<x.spec<<" ";
  86. cout<<x.years<<" ";
  87. }
  88.  
Success #stdin #stdout 0s 544KB
stdin
3
ass askdk 45 76
sjkf sfjf 56 43
skii drwf 12 34
stdout
ass askdk 45 76
sjkf sfjf 56 43
skii drwf 12 34
------------
skii drwf 12 34
ass askdk 45 76
sjkf sfjf 56 43
------------
ass askdk 45 76 
-------------
153