历年北京理工大学复试上机题题目汇总:
http://blog.csdn.net/u014552756/article/details/78505845
1、某人有 8 角的邮票 5 张,1 元的邮票 4 张,1元 8 角的邮票 6 张,用这些邮票中的一张或若干张可以得到多少种不同的邮资?
参考链接:set用法(set中没有重复的数据)
#include<iostream>
#include<set>
using namespace std;
int main()
{
double a,b,c;
int i=1;
set<double> se;
cout<<"可以组成的钞票额度为:"<<endl;
for(a=0; a<=5; a++)
for(b=0; b<=4; b++)
for(c=0; c<=6; c++)
{
cout<<c*1.8+b+a*0.8<<" ";
se.insert(c*1.8+b+a*0.8);
i++;
}
cout<<endl<<"总共组成了:"<<i<<"种"<<endl;
cout<<"去重后:"<<endl;
set<double>::iterator it;
for(it=se.begin(); it!=se.end(); it++)
cout<<(*it)<<" ";
cout<<endl<<"总共组成了:"<<se.size()<<"种"<<endl;
return 0;
}
2、 输入 n 值, 使用递归函数,求杨辉三角形中各个位置上的值,按照如下形式打印输出图形。例如:当n=6 时。
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
#include<iostream>
using namespace std;
int fun( int i,int j)
{
if(i==1||j==1||j==i)
return 1;
else
return fun(i-1,j)+fun(i-1,j-1);
}
int main()
{
int n,i,j;
cout<<"请输入 n 的值:"<<endl;
cin>>n;
for(i=1; i<=n; i++)
{
for(j=1; j<=n-i; j++)
cout<<" ";
for(j=1; j<=i; j++)
cout<<fun(i,j)<<" ";
cout<<endl;
}
return 0;
}