数据结构算法与分析

 

   题(1) 试写一算法,自大至小依次输出顺序读入的三个整数X,Y和Z的值。 
  题(2)已知k阶裴波那契序列的定义为:
 
 
 
 
 
 
    试编写k阶裴波那契序列的第 项值的函数算法,k和m均以值调用的 形式在函数参数表中出现。
题(3) 假设有A,B,C,D,E五个高等院校进行田径对抗赛,各院校的单项成绩均已存入计算机,并构成一张表,表中每一行的形式为:
 

 项目名称

 
性      别
 校      名
成     绩
得     分

 

 编写算法,处理上述表格,以统计各院校的男、女总分和团体总分,并输出。
题(4) 试编写算法,计算 i !. 2 i的值并存入数组a[0…arrsize - 1] 的第i- 1个分量中(I= 1,2,….,n)。假设计算机中允许的整数最大值为maxint, 则当n>arrsize 或对某个k(1≤k≤n)使     k!. 2k >maxint 时,应按出错处理,注意选择你认为较好的出错处理方法。
 
题(1)
void print_descending(int x,int y,int z
{
 scanf("%d,%d,%d",&x,&y,&z);
 if(x<y) x<->y; 
 if(y<z) y<->z;
 if(x<y) x<->y; 
 printf("%d %d %d",x,y,z);
}//print_descending
题(2)
Status fib(int k,int m,int &f
{
  int tempd;
  if(k<2||m<0) return ERROR;
  if(m<k-1) f=0;
  else if (m==k-1) f=1;
  else
  {
    for(i=0;i<=k-2;i++) temp[i]=0;
    temp[k-1]=1; //初始化
    for(i=k;i<=m;i++) 
    {
      sum=0;
      for(j=i-k;j<i;j++) sum+=temp[j];
      temp[i]=sum;
    }
    f=temp[m];
  }
  return OK;
}//fib
 
题(3)
typedef struct{
                     char *sport;
                    enum{male,female} gender;
                    char schoolname; //校名为'A','B','C','D'或'E'
                     char *result;
                    int score;
                  } resulttype;
typedef struct{
                     int malescore;
                    int femalescore;
                    int totalscore;
                  } scoretype;
void summary(resulttype result[ ])//求各校的男女总分和团体总分,假设结果已经储存在result[ ]数组中
{
  scoretype score;
  i=0;
  while(result[i].sport!=NULL)
  {
    switch(result[i].schoolname)
    {
      case 'A':
        score[ 0 ].totalscore+=result[i].score;
        if(result[i].gender==0) score[ 0 ].malescore+=result[i].score;
        else score[ 0 ].femalescore+=result[i].score;
        break;
      case 'B':
        score.totalscore+=result[i].score;
        if(result[i].gender==0) score.malescore+=result[i].score;
        else score.femalescore+=result[i].score;
        break;
      ……    ……    ……
    }
    i++;
  }
  for(i=0;i<5;i++)
  {
    printf("School %d:/n",i);
    printf("Total score of male:%d/n",score[i].malescore);
    printf("Total score of female:%d/n",score[i].femalescore);
    printf("Total score of all:%d/n/n",score[i].totalscore);
  }
}//summary
题(4) 
Status algo119(int a[ARRSIZE])// i!*2^i 序列的值且不超过 maxint
{
  last=1;
  for(i=1;i<=ARRSIZE;i++)
  {
 a[i-1]=last*2*i;
   if((a[i-1]/last)!=(2*i)) reurn OVERFLOW;
   last=a[i-1];
   return OK;
  }
}//algo119

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值