第1个回答 2013-04-14
#include<stdio.h>
int main(){
double a[10],sum = 0.0,average = 0.0;;
int i;
double maxscore,minscore;//最高分和最低分
printf("请输入十位裁判的分数:\n");
for(i = 0; i < 10; i++)
scanf("%lf",&a[i]);
maxscore = a[0];
minscore = a[0];
for(i = 1; i < 10; i++)
{
if(a[i] > maxscore)
maxscore = a[i];
if(a[i] < minscore)
minscore = a[i];
sum += a[i];
}
average = (sum - maxscore - minscore)/ 8;
printf("选手的最终得分为%.2lf\n",average);
return 0;
}本回答被提问者采纳
第2个回答 2020-06-02
#include
#include
#include
#include
#include
//定义二叉树节点数据结构
typedef
struct
node{
struct
node
*lchild;
char
data;
struct
node
*rchild;
}bitnode,*bitree;
//构造截取子串函数,start从零开始.
char
*get_substr(char
*strDest,int
start,int
end)
{
if(start>end)
return
NULL;
//如果左子树或右子树为空则返回空串
char
*strSub;
//字串指针
strSub=(char*)malloc((end-start+2)*sizeof(char));
int
i;
for(i=start;i<=end;i++)
strSub[i-start]=strDest[i];
strSub[end-start+1]='\0';
return
strSub;
}
//前序遍历二叉树,并输出
void
preorder_traverse(bitree
bt){
if(bt
!=
NULL)
{
printf("%c",bt->data);
preorder_traverse(bt->lchild);
preorder_traverse(bt->rchild);
}
}
//根据中序和后序遍历结果递归构造二叉树,并返回根指针
bitree
create_bitree(char
*inorder,char
*postorder)
//inorder和postoeder分别为中序和后序遍历的结果字符串
{
if(inorder==NULL
||
postorder==NULL)
return
NULL;
//空串则返回空树
char
root_data;//根节点字符
char
*lchild_instr,*lchild_postr,*rchild_instr,*rchild_postr;//左子树和右子树中序及后序字符串
int
i,len;
len=strlen(inorder);
//中序和后序字符串长度相等
bitree
new_bitree=(bitree)malloc(sizeof(bitnode));
root_data=postorder[len-1];//树的根节点必然为中序遍历的最后一个字符
new_bitree->data=root_data;
for(i=0;i<len;i++)
//找到根节点在中序遍历中位置
{
if(inorder[i]==root_data)
break;
}
//确定左子树和右子树中序及后序字符串
lchild_instr=get_substr(inorder,0,i-1);
lchild_postr=get_substr(postorder,0,i-1);
rchild_instr=get_substr(inorder,i+1,len-1);
rchild_postr=get_substr(postorder,i,len-2);
//递归构造子树
new_bitree->lchild=create_bitree(lchild_instr,lchild_postr);
new_bitree->rchild=create_bitree(rchild_instr,rchild_postr);
return
new_bitree;
}
void
main(){
char
inorder[20]="BDCEAFHG";
char
postorder[20]="DECBHGFA";
bitree
root;
root=create_bitree(inorder,postorder);
//输出前序遍历结果
printf("the
binary
tree
in
preorder
is:\n");
preorder_traverse(root);
_getch();
}
//满意的话别忘了多加点分哈
第3个回答 2013-04-14
float avag(float a[], int n)
{
float max=-1;
float min=100000000;
float sum=0;
int i;
if(n <= 2) //error
return -1.0;
for(i= 0; i< n;i++)
{
sum+=a[i];
if(a[i]>max) max = a[i];
if(a[i]<min) min = a[i];
}
return (sum-max-min)/(n-2);
}