计科学硕

1.将一个长度为10的数列,最大值放第一个,最小值放最后一个。
                    输入:1 2 3 4 5 9 0 7 8 6
                    输出:9 2 3 4 5 1 6 7 8 0

#include <iostream>;
using namespace std;int num[10];int main() {for (int i = 0; i <= 9; i++) {cin >> num[i];}int maxValue = -99999;int maxIndex = 0;int minValue = 99999;int minIndex = 0;for (int i = 0; i <= 9; i++) {if (num[i] > maxValue){maxValue = num[i];maxIndex = i;}else if (num[i] < minValue){minValue = num[i];minIndex = i;}}swap(num[0], num[maxIndex]);swap(num[9], num[minIndex]);for (int i = 0; i <= 9; i++) {cout << num[i] << " ";}cout << endl;}

2.输入几个数,把素数找出,由大到小排序输出。
                    输入:6 11 5 10 13 35 9
                    输出:5 11 13


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;bool isPrime[1001];
vector<int> prime;void initialize(int maxIndex) {// 0 1 不是素数,2 ~ 最大下标 默认是素数isPrime[0] = isPrime[1] = 0;for (int i = 2; i <= maxIndex; i++) {isPrime[i] = 1;}// 素数的倍速,不是素数for (int i = 2; i <= maxIndex; i++) {if (isPrime[i] == 1) {for (int j = 2 * i; j <= maxIndex; j += i) {isPrime[j] = 0;}}}return ;
}int toInt(string s) {stringstream ss(s);int a ;ss >> a;return a;
}int main() {initialize(1000);string s;string sub;int t;getline(cin, s);int index = s.find(" ");while (index != -1) {sub = s.substr(0, index); // pos lent = toInt(sub);//cout << t << endl;if (isPrime[t]) {prime.push_back(t);}s.erase(0, index + 1); // pos len, 连带空格也删掉index = s.find(" ");}if (s.size() > 0) {t = toInt(s);if (isPrime[t]) {prime.push_back(t);}}//cout << "ok" << endl;//cout << prime.size() << endl;sort(prime.begin(), prime.end());for (int i = 0; i <= prime.size() - 1; i++){cout << prime[i] << " ";}cout << endl;}

3.输入考生的学号、姓名、考试成绩。输入5个考生信息,按照成绩大小升序和逆序输出。使用指针函数,函数调用和结构体。

指针函数 == 返回值为 指针

函数指针 ==一个指针变量,该指针指向这个函数

指针函数本质是一个函数,其返回值为指针。
函数指针本质是一个指针,其指向一个函数。

void* : 可以用其 指代任何类型的指针。 可以当int* double* 使用!

因为指针只占1个字节的空间,存放的是首地址,到底是int的首地址,还是double的首地址,看具体情况。

使用时:不能用void指针直接进行操作;只能转换成对应类型指针后,才能操作

int a = 5;
    void* p = & a;
    cout << * (int*)p  << endl;


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;// Student 代表结构体
// PStudent 代表 结构体的指针,开辟内存空间专门存放内存地址,存放Student变量的第一个地址。
typedef struct Student {int no;string name;double score;
}Student, * PStudent;vector<PStudent> res; // 存放student的指针PStudent getPStudent(int no, string name, double score) {// 一定要用malloc,在函数内部申请变量 就是犯罪!!PStudent t = (PStudent)malloc(sizeof(Student));(*t).no = no;(*t).name = name;(*t).score = score;return t;
}bool compare(PStudent a, PStudent b) {return (*a).score < (*b).score;
}int main() {int no;string name;double score;for (int i = 1; i <= 5; i++) {cin >> no >> name >> score ;PStudent t = getPStudent(no, name, score);res.push_back(t);}sort(res.begin(), res.end(), compare);for (int i = 0 ; i <= res.size() - 1; i++) {cout << (*res[i]).no << " " << (*res[i]).name << " " << (*res[i]).score << endl;}for (int i = res.size() - 1 ; i >= 0; i--) {cout << (*res[i]).no << " " << (*res[i]).name << " " << (*res[i]).score << endl;}
}
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;void show(int a){cout << "a is " << a << endl;
}
void (*p_show)(int a);void getHello(){cout << "hello" << endl;return ;
}
void (*p_getHello)();int main() {p_show = show;(*p_show)(255);p_getHello = getHello;(*p_getHello)();
}

软工农信:1.输入一个整数n,输出该整数中重复的数字,如果没有重复出现的数字则输出 No repeat number! 
                    输入:2312626
                    输出:2 6

#include <iostream>using namespace std;long long n;
int num[10]; // 0 ~ 9
int cnt;int main(){for (int i = 0; i <= 9; i++){num[i] = 0;}cnt = 0;cin >> n;while (n > 0){int wei = n % 10;num[wei] ++;cnt++;//cout << wei << endl;n /= 10;}if (!cnt){cout << "No repeat number!" << endl;}else {for (int i = 0; i <= 9; i++){if (num[i] >= 2){cout << i << " ";}}cout << endl;}}

2.输入一个字符串,统计字符串中大、小写字母,数字及其他字符出现的次数
                    输入:abcd123![]ABC
                    输出:3 4 3 3

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;int cntUp = 0;
int cntLow = 0;
int cntNum = 0;
int cntOther = 0;int main() {string s;cin >> s;for (int i = 0; i <= s.size() - 1; i++) {if (s[i] >= 'a' && s[i] <= 'z') {cntLow++;} else if (s[i] >= 'A' && s[i] <= 'Z') {cntUp++;} else if (s[i] >= '0' && s[i] <= '9') {cntNum++;} else {cntOther++;}}printf("%d %d %d %d\n", cntUp, cntLow, cntNum, cntOther);}

3.输入5个字符串,对字符串排序并输出

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;vector<string> res;bool compare(string s1, string s2){return s1[0] < s2[0];
}int main(){res.clear();string t;for (int i = 1; i <= 5; i++){cin >> t;res.push_back(t);}sort(res.begin(), res.end(), compare);for (int i = 0; i <= res.size() - 1; i++){cout << res[i] << " ";}cout << endl;}

复试机试【XN2018】相关推荐

  1. 华科00年计算机考研复试机试

    [1]输入n, 求y1=1!+3!+...m!(m是小于等于n的最大奇数) y2=2!+4!+...p!(p是小于等于n的最大偶数) 参考代码: #include<stdio.h> int ...

  2. 华师大计算机在线作业,华东师范大学计算机考研复试机试习题

    华东师范大学计算机考研复试机试习题 华东师范大学计算机考研:计算机系.数据学院复试机试历年真题以及AC代码.历年学长总结得到.适用学院:计算机学院.数据学院.软件学院也可参考.sum/=10;prin ...

  3. 1004: 惠民工程 (2013年中南大学研究生复试机试 )

    1004: 惠民工程 时间限制: 1 Sec  内存限制: 128 MB 提交: 404  解决: 81 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 市政府"惠民工程&q ...

  4. 计算机保研面试基础知识,华科计算机保研复试机试题目

    华中科技大学复试机试题目 2008年 一. 1.狼过河问题(运用到回溯) 2.统计文件中单词数目 3.N阶楼梯上楼问题:一次可以走两阶或一阶,问有多少种上楼方式.(递归) 4.链表操作 二. 第一个是 ...

  5. 华科计算机保研复试题目,华科计算机保研复试机试题目2.doc

    华中科技大学复试机试题目 2008年 一. 1.狼过河问题(运用到回溯) 2.统计文件中单词数目 3.N阶楼梯上楼问题:一次可以走两阶或一阶,问有多少种上楼方式.(递归) 4.链表操作 二. 第一个是 ...

  6. 【超级完整】北京理工大学计算机复试机试历年真题答案2003年-2018年

    本人已经把该博客代码部分整理,在另一篇博客中: [超级完整-更正版]北京理工大学计算机专业复试机试历年真题答案2003年-2018年 目 录 1-2003两个空间坐标求球的体积 1 2-2003计算某 ...

  7. 上海交大计算机考研复试,上海交大计算机考研复试机试

    上海交大 计算机考研 SJTU-CS 复试机试 (2005-2010) 题目 我自己在准备考研时曾做了下06,07,08,09年的题目,并且在博客中提供了一个参考的题解,10年的题目以及11年保研的题 ...

  8. 211大学计算机复试不机试,复试机试之上海交通大学计算机研究生机试真题.doc...

    复试机试之上海交通大学计算机研究生机试真题 (你自己回去改格式啊,这个有多重繁杂字体,你自己改好看点~~还有知识05年到11年的)复试机试之2011年上海交通大学计算机研究生机试真题 (2012-02 ...

  9. 计算机复试机试题目与答案,二零一四年华中科技大学计算机研究生复试机试题目...

    2014年华中科技大学计算机研究生复试机试题目 2014年研究生复试终于结束了,因为自己寻找往年机试题目的经历很艰难,故我希望为之后的学弟,学妹们提供一些资料,以供参考. 今年机试题目总共有3道,编译 ...

  10. 清华计算机考研复试机试,请问清华考研计算机复试考什么

    满意答案 vwild 2015.06.01 采纳率:55%    等级:11 已帮助:5245人 清华大学计算机专业研究生复试有体检,专业课笔试,英语面试,上机考试,导师面试等几个部分.而复试的比例一 ...

最新文章

  1. Exception Handling Best Practices in .NET
  2. java 高级数据类型_java 数据类型(上):分类
  3. NSWindowController的初始化创建代码
  4. php 输入汉字自动带出拼音和英文
  5. 网络资产管理系统_固定资产管理系统网络版的各种语言翻译
  6. js 调用webservice接口
  7. (一)带有图像到图像转换的移动风格迁移
  8. 彩色图+车牌颜色测试结果分析
  9. Message消息提示组件的原理
  10. unix 网络编程总结
  11. 推荐一个国外的关于奥运报道的网站.
  12. Web开发必须知道的知识点
  13. 项目经理应该知道的三种项目管理技术
  14. C语言输出三位数的水仙花数
  15. 漫画研发之九:浑水好摸鱼
  16. 制作openstack镜像(qcow2格式的win10系统)
  17. 软件测试 - 功能测试Ⅱ
  18. Android:简单实现美女扒衣服小游戏
  19. 框图c语言程序,C语言程序设计框图
  20. 用星号(*)打出一个三角形

热门文章

  1. python爬斗鱼直播房间名和主播名_斗鱼爬虫,爬取颜值频道的主播图片和名字
  2. 【读书笔记】读《自制力:如何掌控自己的时间与生活?》 —— 25条自制力掌控法则
  3. 热红外探测器的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  4. html怎么去除左边的圆点,在Html的CSS中去除标签前面小黑点以及ul、LI部分属性方法...
  5. QtWeb-用于Webkit测试的替代浏览器
  6. 触发器(Trigger)
  7. 大学生社交网络问卷调查,社交情况问卷调查报告
  8. java输入月份获得该年的这个月最后一个工作日是多少号(星期一到星期五)
  9. java之hashTab
  10. 【Windows、Git问题】detected dubious ownership in repository 问题解决