软微学院2016年硕士复试机试:
1.在考试过程中不允许上网搜索资料,不允许携带电子资料、书面资料进入考场;
2.对于要求设计并实现的算法或程序的问题,最终程序需要调试通过;
3.程序设计语言可以为C、C++ 或Java,代码风格将作为评分标准之一。
4.最终只需提交源程序,每道题一个文件夹,所有文件夹打包以姓名考号命
一、程序填空题( 20分)。
编写程序,输出1000以内的所有完数及其因子。
说明:所谓完数是指一个整数的值等于它的因子之和。
例如“6的因子是1、2、3,而6=1+2+3,故6是一个完数。
二、程序改错题( 20分)。
计算数组元素中值为正数的平均值(不包括0,0为数据结束的标志)。例如:数组中元素的值依次为39,-47, 21, 2, -8, 15,0, 则程序的运行结果为19.250000。
三、算法编程试题(以下两题任意选做一道,30分)。
1.编写程序,在随机输入一一个数组后,实现对该数组的排序,输出排序后的新数组。
#include<iostream>
using namespace std;
void print(int arr[], int n){//打印数组
for(int j= 0; j<n; j++){
cout<<arr[j] <<" ";
}
cout<<endl;
}
void BubbleSort(int arr[], int n){//冒泡排序:每次把最大的放到最后
for (int i = 0; i < n - 1; i++){
for (int j = 0; j < n - i - 1; j++){
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main(){
int n; //要排序的数字总数n
cout<<"要排序的数字总数n:"<<endl;
cin>>n;
int s[n];
cout<<"输入要排序的数字:"<<endl;
for(int k=0;k<n;k++){//输入要排序的数字;
cin>>s[k];
}
cout<<"排序前结果:"<<endl;
print(s,n);
BubbleSort(s,n);
cout<<"排序后结果:"<<endl;
print(s,n);
}
2.编写程序,将m(1≤m≤10)个字符串连接起来,组成一个新的字符串,并输出该字符串。
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int n;
cin>>n;
string str[n];
string n_str;
for(int i=0;i<n;i++){
cin>>str[i];
n_str+=str[i];
}
cout<<n_str<<endl;
return 0;
}
四、应用编程题(以下两题任意选做一道,30分)
1.从键盘上随机输入一 个字符串,要求将字符串中的的数字全部过滤掉,大写变小写,即:输入字符串“AD23def4jj4",则输出为“addefj"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
getline(cin, a);//输入字符串
for (int i = 0; i < a.size(); i++)
{
if (a[i] >= 'a'&&a[i <= 'z'])//小写不变 {
a[i] = a[i];
cout<<a[i];
}
else if (a[i] >= 'A'&&a[i <= 'Z'])//大写变小写
{
a[i] = a[i] + 32;
cout<<a[i];
}
else{
continue;
}
}
}
2.从键盘上首先输入一个数组大小n,要求n>2;然后随机输入n个整数构成一个初始数组,然后将数组最前面的元素和最后面的元素依次互换位置,例如将数组第.1个元素与第n个元素互换,第2个元素与第n-1个元素互换,第3个元素与第n-2个元素互换,依次类推,最后生成一个新的数组,请分别输出最初的数组和最后生成的数组。
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char str1[1000];
gets(str1);
int len_str=strlen(str1);
char tmp;//注意是字符串
for(int i=0;i<len_str/2;i++){
tmp=str1[i];
str1[i]=str1[len_str-1-i];
str1[len_str-1-i]=tmp;
}
cout<<str1;
return 0;
}