1、1 实现两个N*N矩阵的乘法,矩阵由一维数组表示:
#include 2、 for(k=0;k 3、 找到单向链表中间那个元素,如果有两个则取前面一个
#include 4、 while(0!=val)
{
sum++;
curr->next = new node;
curr = curr->next;
curr->value = val;
curr->next = NULL;
cin>>val;
}
curr = head;
for(i=0;i<(sum+1)/2;i++)
{
curr = curr->next;
}
cout<<"中间的数字是:"< 5、r->value< 6、 printf("%ld\n", GetMax(array, 4));
return 0;
}
long GetMax(int array[], int len)
{
int positive_num = 0;
int negative_num = 0;
int zero_num = 0;
int positive_min = INT_MAX;
int negative_max = INT_MIN;
int negative_min = 0;
int count = 1;
7、int i;
if(!array)
{
printf("array must not be NULL\n");
exit(-1);
}
if(len < 1)
{
printf("len should be bigger than 0\n");
exit(-1);
}
for(i = 0; i < len; i++)
{
if(array[i] > 0)
{
8、 positive_num++;
positive_min = (positive_min < array[i])? positive_min: array[i];
}
else if(array[i] == 0)
{
zero_num++;
}
else
{
negative_num++;
negative_max = (negative_max 9、> array[i])? negative_max: array[i];
negative_min = (negative_min < array[i])? negative_min: array[i];
}
}
if(zero_num > 1) return 0;
else if(zero_num == 1)
{
if(negative_num % 2 == 1) return 0;
else
{
return 10、 GetMultiply(array, len, 0, 1);
}
}
else
{//no zero
if(negative_num % 2 == 1)
{
return GetMultiply(array, len, negative_max, 1);
}
else
{
if(positive_num > 0)
return Ge 11、tMultiply(array, len, positive_min, 1);
else
return GetMultiply(array, len, negative_min, 1);
}
}
}
long GetMultiply(int array[], int len, int tag, int count)
{
long multiply = 1;
int i;
if(!array)
{
printf("array m 12、ust not be NULL\n");
exit(-1);
}
if(len < 1)
{
printf("len should be bigger than 0\n");
exit(-1);
}
for(i = 0; i < len; ++i)
if(array[i] == tag && count > 0)
count--;
else multiply *= array[i];
r 13、eturn multiply;
}
4 输出二进制中1的个数
#include 14、 *p;
// *p=b[1];
//printf("b is %d",*p++);
while(m){
count++;
m=m&(m-1);
// cout< 15、esetTime(int *year,int *month,int *date,int *hour,int *minute,int *second)
{
int dayofmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(*year<0||*month<1||*month>12||*date<1||*date>31||*hour<0||*hour>23||*minute<0||*minute>59||*second<0||*second>60)
return -1;
if(*year%400==0||*year%100= 16、0&&*year%4==0)
dayofmonth[1]=29;
*second +=1;
if(*second>=60)
{
*second=0;
*minute +=1;
if(*minute>=60)
{
*minute=0;
*hour +=1;
if(*hour>=24)
{
*hour=0;
*date +=1;
if(*date>dayofmonth[*month-1])
{
*date=1;
*month +=1;
if(*mo 17、nth >12)
{
*month=1;
*year +=1;
}
}
}
}
}
cout <<*year<<' '<<*month<<' '<<*date<<' '<<*hour <<' '<<*minute<<' '<<*second;
return 1;
}
int main()
{
int y1=2004;
int m1=2;
int d1=28;
int h1=23;
int mm=59;
int se=59;
int n;
n=ResetTime(&y1 18、m1,&d1,&h1,&mm,&se);
return 0;
}
6 编写一个函数,实现把C++/C程序代码中的注释去掉,并把结果返回。
#include 19、e_t len;
p=buf;
end=p+size;
sq_start=NULL;
dq_start=NULL;
lc_start=NULL;
bc_start=NULL;
while(p 20、 {
len=p++-sq_start;
if(len==2&&*(sq_start+1)=='//')
{
continue;
}
sq_start=NULL;
}
break;
}
}
}待续
7 一个5位数字ABCDE*4=EDCBA,这5个数字不能重复,编程求出这个是数字是多少
程序如下所示:
#include






