博文
一道c++竞赛题(2005-07-28 13:01:00)
摘要:已知n个整数 x1,x2,…..xn, 以及一个整数k (k<n)。从 n 个整数中任选k个整数组合相加,可分别得到一系列的和。例如当 n=4, k=3,4个整数分别为3,7,12,19 时,可得全部的组合为:
3+7+12=22 3+7+19=29
7+12+19=38 3+12+19=34。
现在,要求你计算出和为素数的组合数有多少种。例如上例,只有一种组合的和为素数:(3+7+19=29)。
输入:
n, k(1≤n≤20,k<n)
x1,x2,…xn(1≤xi≤5000000)
输出:
一个整数(满足条件的种数)
输入输出样例:
输入:
4 3
7 12 19
输出:
1
源程序:
#include<iostream>
#include<math.h>
const int N=21;
using namespace std;
int issushu(long num)
{
for(long i=2;i<=sqrt(num);i++)
if(num%i==0)
return 0;
return 1;
}
long total......
一个题目(c++)(2005-07-18 23:40:00)
摘要:在论坛上看到这样的题目:
任意一个正整数的立方都可以写成一串连续奇数和。例如:
13*13*13=157+159+。。。。。。+179+181+183
这道题的算法是:任意输入的正整数的平方为x,那么一串连续奇数的第一个数应为x减去这个正整数减一,
按等差为2的数列直到x加上这个正整数减一.例如:如果输入为12,即求12的立方,
则应为:144-(12-1)=133,135,137,139.........144+(12-1)=155.
程序:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int num;
cout<<"plese input the num:";
cin>>num;
int num2=pow(num,2);
int sum=num2-(num-1),sum2=num2+num-1;
cout<<endl<<"the result is:"<<endl;
cout<<num<<"*"<<num<<"*"<<num<<"="<<sum;
while(sum<=sum2)
{
 ......
n个数的最小公倍数(2005-07-18 23:15:00)
摘要:
#include<stdio.h>
#define N 3/*随意改变这个值实现n的变化*/
int yueshu[15];
int zuixiao(int b[],int count)
{
int i=0,small=32667;
for(;i<count;i++)
if(b[i]<b[0])
small=i;
if(small==32667)
return 0;
else
return small;
}
int xingma(int number,int i)
{
if(number%i==0)
return 1;
else
return 0;
}
int zdgyshu(int c[],int x,int num)
{
int i=0,k=0,j,data,count=0,dataelse=0;
for(i=2;i<=c[num];i++)
if(xingma(c[num],i))
{
yueshu[k]=i;
k++;
}
for(i=0;i<k;i++)
{
data=c[i];
for(j=0;j<x;j++)
{
if(j==num)
continue;
else
{
if(xingma(c[j],data))
count++;
}
}
if(count==x-1)
dataelse=data;
}
if(dataelse!=0)
return dataelse;
else
return 0;
}
main()
{
int array[N],i,public_mnum,public_mtime,smallest,sum=1;
clrscr();
printf("please input %d numbers:&quo......
C++(类的静态成员运用)(2005-07-15 12:07:00)
摘要:#include<iostream>
using namespace std;
class Box
{
public:
Box();
Box(double lengthvalue,double breadthvalue,double heightvalue);
double volume()const;
int comparevolume(const Box& otherbox)const;
int getobjectcount()const {return objectcount;}
private:
static int objectcount;
double length;
double breadth;
double height;
};
Box::Box()
{
cout<<endl<<"Default constructor called"<<endl;
++objectcount;
length=breadth=height=1;
}
Box::Box(double lengthvalue,double breadthvalue,double heightvalue):length(lengthvalue),
breadth(breadthvalue),height(heightvalue)
{
cout<<endl
<<"constructor called"
<<endl;
......
2005年下半年软件设计师考试大纲(2005-07-14 22:11:00)
摘要:
一、考试说明
1.考试要求:
(1) 掌握数据表示、算术和逻辑运算;
(2) 掌握相关的应用数学、离散数学的基础知识;
(3) 掌握计算机体系结构以及各主要部件的性能和基本工作原理;
(4) 掌握操作系统、程序设计语言的基础知识,了解编译程序的基本知识;
(5) 熟练掌握常用数据结构和常用算法;
(6) 熟悉数据库、网络和多媒体的基础知识;
(7) 掌握C程序设计语言,以及C++、Java、Visual、Basic、Visual C++中的一种程序设计语言;
(8) 熟悉软件工程、软件过程改进和软件开发项目管理的基础知识;
(9) 熟悉掌握软件设计的方法和技术;
(10) 掌握常用信息技术标准、安全性,以及有关法律、法规的基本知识;
(11) 了解信息化、计算机应用的基础知识;
(12) 正确阅读和理解计算机领域的英文资料。
2.通过本考试的合格人员能根据软件开发项目管理和软件工程的要求,按照系统总体设计规格说明书进行软件设计,编写程序设计规格说明书等相应的文档,组织和指导程序员编写、调试程序,并对软件进行优化和集成测试,开发出符合系统总体设计要求的高质量软件;具有工程的实际工作能力和业务水平。
3.本考试设置的科目包括:
(1) 计算机与软件工程知识,考试时间为150分钟,笔试;
(2) 软件设计,考试时间为150分钟,笔试。
二、考试范围
考试科目1:计算机与软件工程知识
1.计算机科学基础
1.1 数制及其转换
· 二进制、十进制和十六进制等常用制数制及其相互转换
1.2 数据的表示
· 数的表示(原码、反码、补码、移码表示,整数和实数的机内表示,精度和溢出)
· 非数值表示(字符和汉字表示、声音表示、图像表示)
· 校验方法和校验码(奇偶校验码、......
c++(类大小的测定)(2005-07-14 16:32:00)
摘要:
#include<iostream>
using namespace std;
class SizeBox
{
public:
SizeBox();
int totalSize();
private:
char* pMaterial;
double length;
double breadth;
double height;
};
SizeBox::SizeBox():length(1.0),breadth(1.0),height(1.0),pMaterial("Cardboard")
{cout<<endl<<"Default constrcutor called"<<endl;
}
int SizeBox::totalSize()
{
return sizeof(length)+sizeof(breadth)+sizeof(height)+sizeof(pMaterial);
}
int main()
{
SizeBox box;
SizeBox boxes[10];
cout<<endl<<"The data numbers of a box occupy"<<box.totalSize()<<"bytes.";
cout<<endl<<"A singal box object occupies"<<sizeof SizeBox<<"bytes.";
cou......
c++(面向对象关于类的盒子问题)(2005-07-13 23:04:00)
摘要:#include<iostream>
using namespace std;
class Box
{
public:
Box(double lengthvalue=1.0,double breadthvalue=1.0,double heightvalue=1.0);
double volume();
int comparevolume(Box& otherbox);
private:
double length;
double breadth;
double height;
};
Box::Box(double lengthvalue,double breadthvalue,double heightvalue):length(lengthvalue),
breadth(breadthvalue),height(heightvalue)
{
cout<<endl
<<"constructor called"
<<endl;
length=lengthvalue;
breadth=breadthvalue;
height=heightvalue;
}
double Box::volume()
{
return length......
c++(最大公约数和最小公倍数)(2005-07-12 13:27:00)
摘要:#include<iostream>
using namespace std;
int main()
{
int m=0,n=0;
cout<<endl
<<"请输入两个数(整型,从小到大):";
cin>>n>>m;
while(n>m)
{
cout<<endl
<<"输入格式错误,请重新输入.:";
cin>>n>>m;
}
int m1=m;
int n1=n;
int i=m%n;
while(i!=0)
{
m=n;
n=i;
 ......
c++(冒泡排序)(2005-07-12 12:35:00)
摘要:#include<iostream>
#define swap(x,y,t)((t)=(x),(x)=(y),(y)=(t))
using namespace std;
const int N=10;
void sort(int b[],int count);
int main()
{
int a[N];
cout<<endl
<<"please input the "<<N<<"numbers:"<<endl;
for(int i=0;i<N;i++)
cin>>a[i];
cout<<endl
<<"the original numbers you have inputed are: "<<endl;
for(i=0;i<N;i++)
cout<<" "<<a[i];
cout<<endl
<<"After sorting the numbers ,the numbers are:"<<endl;
&nb......
c++(模板和重载)(2005-07-10 15:28:00)
摘要:#include<iostream>
#include<iomanip>
using namespace std;
template <class T> T larger(T a,T b);
template<>long* larger<long*>(long* a,long* b);
template<class T>T larger(const T array[],int count);
template<class TReturn,class TArg>TReturn larger(TArg a,TArg b);
int main()
{
cout<<endl;
cout<<"the larger between 1.2 and 3.5 is:"<<larger(1.2,3.5)<<endl;
int value=25;
int value1=21;
cout<<"the larger between"<<value<<"and"<<value1<<"is:"<<larger(value,value1)<<endl;
long value3=35;
long value4=25;
cout<<"the larger between"<<value3<<"and"<<value4&l......