北理工计算机复试上机 2012

1.输入10个数,从小到大排序

示例:

输入:1,2,5,7,9,10,45,67,24,26

输出:1,2,5,7,9,10,24,26,45,67

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4
 5     int a[10]={0};
 6     int x=0;
 7     while(x<10){
 8         cin>>a[x];
 9         x++;
10     }
11
12     for(int i=10;i>0;i--){
13         int flag=0;
14         for(int j=1;j<i;j++){
15             if(a[j-1]>a[j]){
16                 int temp=a[j-1];
17                 a[j-1]=a[j];
18                 a[j]=temp;
19                 flag=1;
20             }
21         }//for
22         if(flag==0)break;
23     }
24
25
26     for(int k=0;k<10;k++){
27         cout<<a[k]<<" ";
28     }
29     cout<<endl;
30 return 0;  }

2.学生有(学号,姓名,性别,年龄),初始化三个学生的信息
  (10,wes,f,23)(20,ert,f,45) (30,str,t,89),
然后对学生信息进行插入和删除处理
例如:
  I 12,rt,f,67
表示插入
12,rt,f,67
D10
表示删除学号为10的学生的信息
每次操作完成以后输出所有学生的信息按学号从大到
小排序
输入:
I 12,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 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 #include<vector>
 5 using namespace std;
 6
 7
 8 class Student{
 9 public:
10     int id;
11     string name;
12     char sex;
13     int age;
14 };
15
16 bool des(Student a,Student b){
17 return a.id>b.id;
18 };
19  int main(){
20     vector<Student> students;
21     Student s;
22     s.id=10;
23     s.name="wes";
24     s.sex=‘f‘;
25     s.age=23;
26     students.push_back(s);
27
28     s.id=20;
29     s.name="wes";
30     s.sex=‘f‘;
31     s.age=23;
32     students.push_back(s);
33
34     s.id=30;
35     s.name="wes";
36     s.sex=‘f‘;
37     s.age=23;
38     students.push_back(s);
39     char order;
40     cout<<"请输入命令"<<endl;
41         vector<Student>::iterator i;
42
43     while(cin>>order){
44         if(order==‘I‘){
45             cout<<"亲输入学生信息"<<endl;
46             cin>>s.id>>s.name>>s.sex>>s.age;
47             students.push_back(s);
48             sort(students.begin(),students.end(),des);
49             for(i=students.begin();i!=students.end();i++)
50             {
51                 cout<<(*i).id<<" "<<(*i).name<<" "<<(*i).sex<<" "<<(*i).age<<endl;
52             }
53         }
54         if(order==‘D‘){
55             cout<<"请输入删除学号"<<endl;
56             int dnum;
57             cin>>dnum;
58             for(i=students.begin();i!=students.end();i++){
59                 if((*i).id==dnum)
60                 {
61                     students.erase(i);
62                     break;
63                 }
64
65             }
66             sort(students.begin(),students.end(),des);
67             for(i=students.begin();i!=students.end();i++)
68             {
69                 cout<<(*i).id<<" "<<(*i).name<<" "<<(*i).sex<<" "<<(*i).age<<endl;
70             }
71         }
72     }
73 return 0;
74 }

3.利用后序和中序确定前序遍历结果
示例:
  输入(按后序、中序):CHBEDA  CBHADE
  输出:ABCHDE

原文地址:https://www.cnblogs.com/PPWEI/p/8453619.html

时间: 2024-08-02 08:34:23

北理工计算机复试上机 2012的相关文章

北理工计算机复试上机 2014

本人也是练习,如果有错误,欢迎指正[email protected],也可留言 1. 系统中有最近打开文件的记录,现用整数表示打开的文件名,且显示最近3个打开的文件,输出文件序列. 示例: 输入:1  输出:1 输入:2  输出:2,1 输入:3  输出:3,2,1 输入:4  输出:4,3,2 输入:1  输出:1,4,3 输入:4  输出:1,4,3 输入:3  输出:1,4,3 1 // 2014_1.cpp : Defines the entry point for the consol

北理工计算机复试上机 2013

1. 求两个数的最大公约数(似乎有个辗转相除法,为什么不用呢,没错,我不会) 示例: 输入:24,18 输出:6 1 // 2013_1.cpp : Defines the entry point for the console application. 2 // 3 #include<iostream> 4 using namespace std; 5 6 int main(int argc, char* argv[]) 7 { 8 int a,b; 9 cout<<"

北理工计算机复试上机 2011

1.输入一组单词(区分大小写),统计首字母相同的单词的个数,相同的单词不累加,输出格式:"字母,个数" 1 // 2011_1.cpp : Defines the entry point for the console application. 2 // 3 4 #include<iostream> 5 #include<vector> 6 #include<string> 7 using namespace std; 8 /** 9 1. 10 输

北理工计算机复试上机 2010

1.输入一串整数,输入命令!要求    1.输入a t在这串整数后添加整数t.    2.输入c \m \n用n替换m.    3.输入d t删除t    4.输入s 排序 1 /** 2 1.输入一串整数,输入命令! 3 要求 4 1.输入a t在这串整数后添加整数t. 5 2.输入c \m \n用n替换m. 6 3.输入d t删除t 7 4.输入s 排序 8 */ 9 #include<iostream> 10 #include<vector> 11 #include<a

北理工计算机复试上机 2009

1.请输入字符串,最多输入4个字符串,要求后输入的字符串排在前面,例如 输入:EricZ 输出:1=EricZ 输入:David 输出:1=David 2=EricZ 1 /** 2 1.请输入字符串,最多输入4个字符串,要求后输入的字符串排在前面,例如 3 输入:EricZ 4 输出:1=EricZ 5 输入:David 6 输出:1=David 2=EricZ 7 */ 8 #include<iostream> 9 #include<list> 10 #include<s

北理工计算机复试上机 2008

1.存储一组姓名,如Apple,Tom,Green,Jack 要求能排序.按字母顺序插入.并显示. 1 /** 2 1.存储一组姓名,如Apple,Tom,Green,Jack 3 要求能排序.按字母顺序插入.并显示. 4 */ 5 #include<iostream> 6 #include<string> 7 #include<vector> 8 #include<algorithm> 9 10 using namespace std; 11 bool i

HDU 1234 (浙大计算机研究生复试上机考试-2005年) 开门人和关门人 (水)

开门人和关门人 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11133    Accepted Submission(s): 5667 Problem Description 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签 到.签离记录,请根据记录找出当天开门和关门的人. Input 测试输入的第一

hdu 4416 水题 浙大计算机研究生复试上机考试-2005年 可是发现自己写代码有问题

Spring3与Hibernate4整合时出现了nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider. hibernate3的时候,用spring来控制sessionfactory用的可以是org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean,因为用的是hibernate4所以照猫画

浙大计算机研究生复试上机考试-2010年 zoj问题

ZOJ问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2984 Accepted Submission(s): 906 Problem Description 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下: 1. zoj能AC: 2. 若字符串形式为xzojx,则也能AC,其中x可以是N