北理工计算机复试上机 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<string>
11
12 using namespace std;
13
14 int main(){
15     list<string> l;
16     string s;
17     int i=0;
18     list<string>::iterator x;
19     cout<<"请输入至多4个字符串,输入00结束"<<endl;
20     int j;
21     while(cin>>s){
22         if(s=="00")break;
23         i++;
24         if(i==4)break;
25         l.push_front(s);
26         for(x=l.begin(),j=1;x!=l.end();x++,j++){
27             cout<<j<<" "<<(*x)<<" ";
28         }
29     }
30     return 0;
31 }//main

2.把上述最后结果保存到Name.txt中

 1 /**
 2 1.请输入字符串,最多输入4个字符串,要求后输入的字符串排在前面,例如
 3 输入:EricZ
 4 输出:1=EricZ
 5 输入:David
 6 输出:1=David 2=EricZ
 7 2.
 8 把上述最后结果保存到Name.txt中
 9 */
10 #include<iostream>
11 #include<list>
12 #include<string>
13 #include<fstream>
14
15 using namespace std;
16
17 int main(){
18     list<string> l;
19     string s;
20     int i=0;
21     list<string>::iterator x;
22     cout<<"请输入至多4个字符串,输入00结束"<<endl;
23     int j;
24     ofstream fs;
25     fs.open("Name.txt");
26
27     while(cin>>s){
28         if(s=="00")break;
29         i++;
30         if(i==4)break;
31         l.push_front(s);
32
33         for(x=l.begin(),j=1;x!=l.end();x++,j++){
34             cout<<j<<" "<<(*x)<<" ";
35         }
36     }
37     for(x=l.begin(),j=1;x!=l.end();x++,j++){
38         fs<<(*x)<<endl;
39     }
40     return 0;
41 }//main

3.先输入一组数,然后输入其分组,按照分组统计出现次数并输出
例如,输入数据3,2,3,8,8,2,3  输入对应分组1,2,3,2,1,3,1
输出:
1={2=0,3=2,8=1}
2={2=1,3=0,8=1}
3={2=1,3=1,8=0}
即每组中各数据出现的次数(抄的,绝妙的设计,高手)

 1 #include<iostream>
 2 #include<deque>
 3 #include<map>
 4 using namespace std;
 5 void show(map<int,int>a)
 6 {
 7     map<int,int>::iterator i;
 8     for(i=a.begin(); i!=a.end(); i++)
 9         cout<<i->first<<"="<<i->second<<" ";
10 }
11 main()
12 {
13     int    a;
14     deque<int> arr1,arr2;
15     map<int,map<int,int>>    mmap;
16     cout<<"请输入数据"<<endl;
17     while(cin>>a)
18     {
19         if(a==0)break;
20         arr1.push_front(a);
21     }
22     cout<<"请输入分组"<<endl;
23     while(cin>>a)
24     {
25         if(a==0)break;
26         arr2.push_front(a);
27     }
28     deque<int>::iterator  it1,it2;
29     for(it1=arr1.begin(),it2=arr2.begin(); it1!=arr1.end(); it1++,it2++)
30         ((mmap[*it2])[*it1])++;
31     map<int,map<int,int>>::iterator    i;
32     for(i=mmap.begin(); i!=mmap.end(); i++)
33     {
34         cout<<i->first<<"={";
35         show(i->second);
36         cout<<"}"<<endl;
37     }
38 }

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

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

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

北理工计算机复试上机 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<<"

北理工计算机复试上机 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 i

北理工计算机复试上机 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

北理工计算机复试上机 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

北京理工大学复试上机--2009

1.请输入字符串,最多输入4 个字符串,要求后输入的字符串排在前面,例如 输入:EricZ 输出:1=EricZ 输入:David 输出:1=David 2=EricZ 输入:Peter 输出:1=Peter 2=David 3=EricZ 输入:Alan 输出:1=Alan 2=Peter 3=David 4=EricZ 输入:Jane 输出:1=Jane 2=Alan 3=Peter 4=David 2.把上述最后结果保存到Name.txt中; #include <iostream> #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所以照猫画