7.28

#include<stdio.h>
#include<math.h>
struct prople{
 int num;
 int name[10];
}p[10000],pmin;//pmin表示最小值 
int main (void)
{
 int i,n,sum=0;
 double half;//half表示平均数的一半
 
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  scanf("%s %d",p[i].name,&p[i].num);
  sum=sum+p[i].num;
 }
 half=sum*1.0/n*0.5;
 pmin=p[0];
 for(i=0;i<n;i++)
 {
  if(fabs(pmin.num-half)>fabs(p[i].num-half))//最接近平均数的一半 
  pmin=p[i];
 }
 printf("%.0f %s",half,pmin.name);
 
 return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int pa,pb;
    int x,a=0,b=0;
    scanf("%d %d",&pa,&pb);
    for(int i=0;i<3;i++){
        scanf("%d",&x);
        if(x==0){
            a++;
        }
        else{
            b++;
        }
    }
    if(pa>pb&&a!=0){
        printf("The winner is a: %d + %d\n",pa,a);
    }
    else if(pa<pb&&b!=0){
        printf("The winner is b: %d + %d\n",pb,b);
    }
    else if(pa<pb&&a==3){
         printf("The winner is a: %d + %d\n",pa,a);
    }
    else if(pb<pa&&b==3){
        printf("The winner is b: %d + %d\n",pb,b);
    }
    return 0;
}

 

posted @ 2023-07-28 19:18  徐星凯  阅读(2)  评论(0编辑  收藏  举报