大厂笔试题
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. using namespace std;
  5. struct student
  6. {
  7. string name;
  8. int old;
  9. int nianji;
  10. };
  11. int main(){
  12. student student1 = {"xiaoming", 10, 2};
  13. student student2 = {"xiaolan", 12, 4};
  14. student student3 = {"xiaohong", 12, 8};
  15. string name;
  16. int old, nianji,j,i;
  17. student studentx;
  18. vector<student> aa;
  19. aa.push_back(student1);
  20. aa.push_back(student2);
  21. aa.push_back(student3);
  22. cout<<"please input the student name"<<endl;
  23. cin>>name;
  24. cout<<"please input the student old"<<endl;
  25. cin>>old;
  26. cout<<"please input the student nianji"<<endl;
  27. cin>>nianji;
  28. studentx.name = name;
  29. studentx.old = old;
  30. studentx.nianji = nianji;
  31. for(i = 0; i < aa.size(); i++){
  32. if(studentx.nianji > aa[i].nianji)continue;
  33. student tmp = aa[i];
  34. aa[i] = studentx;
  35. // cout<<"i = "<<i<<endl;
  36. aa.push_back(studentx);
  37. // cout<<"size "<<aa.size()<<endl;
  38. for(j = aa.size() - 1; j > i + 1; j--){
  39. cout<<"1111111111111111111"<<endl;
  40. aa[j] = aa[j - 1];
  41. cout<<"122222222222222"<<endl;
  42. }
  43. cout<<"122222222222222"<<endl;
  44. aa[j--] = tmp;
  45. break;
  46. }
  47. if(i == aa.size())aa.push_back(studentx);
  48. for(i = 0; i < aa.size(); i++){
  49. cout<<aa[i].name<<endl;
  50. }
  51. return 0;
  52. }