您的位置:首页 > 编程语言

航电oj2013-2015 参考代码

风里雨里 2021-02-22 23:03 127 查看 https://blog.51cto.com/1422175

2013 蟠桃大会

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{

int n,sum,i;
while(scanf("%d",&n)!=EOF)
{
sum = 1;
if(n>1 && n<30)
{
for(i=1; i<n; i++)
{
sum = 2*(sum+1);
}
printf("%d\n",sum);
}
}
return 0;

}

-----------------------------------------------

2014 评委打分

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{

int n,i;
double min,max,sum,avg;
double arr[100];
while(scanf("%d",&n)!=EOF)
{
if(n>2 && n<=100)
{
scanf("%lf",&arr[0]);//第一次的成绩
sum = min = max = arr[0];
for(i=1; i<n; i++)
{
scanf("%lf",&arr[i]);
if(arr[i]>max)
max = arr[i];
if(arr[i]<min)
min = arr[i];
sum += arr[i];
}
avg = (sum - min - max)/(n-2);
printf("%.2lf\n",avg);
}
}
return 0;

}

-----------------------------------------------

2015 偶数求和

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{

int n,m,i,j,sum,count;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1; i<=n;)
{
sum = 0;
count =0;
for(j=1; j<=m&&i<=n; j++)
{
sum += i*2;
count++;
i++;
}
printf("%d",sum / count);
if(i<=n)
printf(" ");
}
printf("\n");
}
return 0;

}

标签: