大厂笔试题
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.
 
 
 

61 lines
1.4 KiB

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
struct student
{
string name;
int old;
int nianji;
};
int main(){
student student1 = {"xiaoming", 10, 2};
student student2 = {"xiaolan", 12, 4};
student student3 = {"xiaohong", 12, 8};
string name;
int old, nianji,j,i;
student studentx;
vector<student> aa;
aa.push_back(student1);
aa.push_back(student2);
aa.push_back(student3);
cout<<"please input the student name"<<endl;
cin>>name;
cout<<"please input the student old"<<endl;
cin>>old;
cout<<"please input the student nianji"<<endl;
cin>>nianji;
studentx.name = name;
studentx.old = old;
studentx.nianji = nianji;
for(i = 0; i < aa.size(); i++){
if(studentx.nianji > aa[i].nianji)continue;
student tmp = aa[i];
aa[i] = studentx;
// cout<<"i = "<<i<<endl;
aa.push_back(studentx);
// cout<<"size "<<aa.size()<<endl;
for(j = aa.size() - 1; j > i + 1; j--){
cout<<"1111111111111111111"<<endl;
aa[j] = aa[j - 1];
cout<<"122222222222222"<<endl;
}
cout<<"122222222222222"<<endl;
aa[j--] = tmp;
break;
}
if(i == aa.size())aa.push_back(studentx);
for(i = 0; i < aa.size(); i++){
cout<<aa[i].name<<endl;
}
return 0;
}