北理工2012年计算机研究生复试上机题
2012-03-26 19:05
375 查看
/*
第一题
要求:
输入十个正整数数字 从小到大排序
输入
1,2,5,7,9,10,45,67,24,26
输出
1,2,5,7,9,10,24,26,45,67
*/
第二题
/*
要求:
学生有(学号,姓名,性别,年龄),初始化三个学生的信息
(10,wes,f,23)(20,ert,f,45)(30,str,t,89),然后对学生信息进行插入和删除处理
例如
I12,rt,f,67表示插入12,rt,f,67
D10 表示删除学号为10的学生的信息
每次操作完成以后输出所有学生的信息按学号从大到小排序
输入:
I12,rt,f,67
输出
(10,wes,f,23),(12,rt,f,67),(20,ert,f,45),(30,str,t,89)
输入:
D10
输出
(12,rt,f,67),(20,ert,f,45),(30,str,t,89)
输入
1,2,5,7,9,10,45,67,24,26
输出
1,2,5,7,9,10,24,26,45,67
*/
第三题
/*
利用后序和中序确定前序遍历的结果
输入(按后序,中序)
CHBEDA
CBHADE
输出
ABCHDE
*/
最后只做出两道,第三道用递归一直调试不出来吗,郁闷啊
第一题
要求:
输入十个正整数数字 从小到大排序
输入
1,2,5,7,9,10,45,67,24,26
输出
1,2,5,7,9,10,24,26,45,67
*/
#include<iostream> #include<algorithm> using namespace std; int main() { int t; int st[100]; char c; for(int i=0;i<9;i++) { cin>>st[i]>>c; } cin>>st[9]; sort(st,st+10); for(i=0;i<9;i++) cout<<st[i]<<","; cout<<st[9]<<endl; return 0; }
第二题
/*
要求:
学生有(学号,姓名,性别,年龄),初始化三个学生的信息
(10,wes,f,23)(20,ert,f,45)(30,str,t,89),然后对学生信息进行插入和删除处理
例如
I12,rt,f,67表示插入12,rt,f,67
D10 表示删除学号为10的学生的信息
每次操作完成以后输出所有学生的信息按学号从大到小排序
输入:
I12,rt,f,67
输出
(10,wes,f,23),(12,rt,f,67),(20,ert,f,45),(30,str,t,89)
输入:
D10
输出
(12,rt,f,67),(20,ert,f,45),(30,str,t,89)
输入
1,2,5,7,9,10,45,67,24,26
输出
1,2,5,7,9,10,24,26,45,67
*/
#include<vector> #include<iostream> #include<string> #include<cmath> #include<sstream> #include<algorithm> using namespace std; class student { public: string num; string name; string sex; int age; void init(string nu,string na,string se,int ag) { num=nu; name=na; sex=se; age=ag; } }; bool cmp(student a,student b) { return a.num.compare(b.num)<0; } vector<student>st; void print() { sort(st.begin(),st.end(),cmp); for(int i=0;i<(st.size()-1);i++) cout<<"("<<st[i].num<<","<<st[i].name<<","<<st[i].sex<<","<<st[i].age<<"),"; cout<<"("<<st[st.size()-1].num<<","<<st[st.size()-1].name<<","<<st[st.size()-1].sex<<","<<st[st.size()-1].age<<")"<<endl; } int main() { /* (10,wes,f,23)(20,ert,f,45)(30,str,t,89) */ student temp; temp.init("10","wes","f",23); st.push_back(temp); temp.init("20","ert","f",45); st.push_back(temp); temp.init("30","str","t",89); st.push_back(temp); string order; while(cin>>order) { if(order[0]=='I') { order.erase(0,1); int pos=order.find(","); string nu=order.substr(0,pos); order.erase(0,pos+1); pos=order.find(","); string na=order.substr(0,pos); order.erase(0,pos+1); pos=order.find(","); string se=order.substr(0,pos); order.erase(0,pos+1); int ag=atoi(order.c_str()); temp.init(nu,na,se,ag); st.push_back(temp); print(); } else { order.erase(0,1); for(int i=0;i<st.size();i++) if(st[i].num==order) st.erase(st.begin()+i,st.begin()+i+1); print(); } } return 0; }
第三题
/*
利用后序和中序确定前序遍历的结果
输入(按后序,中序)
CHBEDA
CBHADE
输出
ABCHDE
*/
#include<iostream> #include<string> using namespace std; typedef struct node { char data; struct node *lchild,*rchild; }BTNode; //利用后序中序确定二叉树 void CreateRoot2(BTNode *&root,string post,string in) { if(post.empty()) return ; root=new BTNode(); root->data=*(post.end()-1); root->lchild=root->rchild=NULL; string pl,pr,il,ir; int pos=in.find(*(post.end()-1)); il=in.substr(0,pos); ir=in.substr(pos+1); pl=post.substr(0,pos); pr=post.substr(pos,ir.size()); CreateRoot2(root->lchild,pl,il); CreateRoot2(root->rchild,pr,ir); } string re; void pre(BTNode *root) { if(root!=NULL) { re+=(*root).data; pre((*root).lchild); pre((*root).rchild); } } int main() { BTNode *root; string post,in; while(cin>>post>>in) { re=""; CreateRoot2(root,post,in); pre(root); cout<<re<<endl; } return 0; }
最后只做出两道,第三道用递归一直调试不出来吗,郁闷啊
相关文章推荐
- 北理工2011年计算机复试上机题(一)
- 北理工2011年计算机复试上机题(二)
- 计算机研究生复试上机题目:顺时针螺旋矩阵简单实现
- 北京理工大学计算机专业研究生复试上机试题(2000-2011)
- 2016河南大学计算机硕士研究生复试上机考试第2题
- 北京邮电大学2009年计算机学院研究生复试上机题
- 北理工2011年计算机复试上机题(三)
- ZOJ问题 HDU - 3788(浙大计算机研究生复试上机考试-2010年 )
- HDU-1231 最大连续子序列 (浙大计算机研究生复试上机考试-2005年 线性dp)
- 浙大计算机研究生复试上机考试(2010)——二叉搜索树(hdu3791)
- 【北理工研究生复试上机题】完数和盈数
- 2016北邮计算机考研复试上机题解
- 牛客网计算机复试上机习题之成绩排序
- HDU 1234 (浙大计算机研究生复试上机考试-2005年) 开门人和关门人 (水)
- Is It Symmetric 浙大计算机研究生保研复试上机考试-2011年
- 浙大计算机研究生复试上机考试-2010年 zoj问题
- 安全密码(2013中南大学研究生复试上机题)
- 西电计算机研究生复试上机题
- 浙大计算机研究生复试上机考试-2009年
- 浙大计算机研究生复试上机考试-2010年 zoj问题