向前走莫回头❤

【openjudge 计算概论(A)】[基础编程练习2]

1:求平均年龄

#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	for(int i=1;i<=n;++i) 
	 {
	 	int x;
	 	scanf("%d",&x);
	 	ans+=x;
	 }
	printf("%.2lf\n",(double)ans/(double)n);
	return 0;
}

2:计算书费

#include<cstdio>
using namespace std;
double d[10]={28.9,32.7,45.6,78,35,86.2,27.8,43,56,65};
int n;
int main()
{
	scanf("%d",&n);
	while(n--)
	 {
	 	double sum=0;
	 	for(int i=0;i<10;++i)
	 	 {
	 	 	int x;
	 	 	scanf("%d",&x);
	 	 	sum+=((double)x*d[i]);
		  }
		printf("%.2lf\n",sum);
	 }
	return 0;
}

3:计算三角形面积

[不明白我写的叉积为什么wa]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double x[4],y[4],a,b,c,p;
double ans;
int main()
{
    cin>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
    a=sqrt((x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1]));
    b=sqrt((x[2]-x[3])*(x[2]-x[3])+(y[2]-y[3])*(y[2]-y[3]));
    c=sqrt((x[1]-x[3])*(x[1]-x[3])+(y[1]-y[3])*(y[1]-y[3]));
    p=(a+b+c)/2;
    ans=sqrt(p*(p-a)*(p-b)*(p-c));
    printf("%.2lf\n",ans);
}

4:骑车与走路

#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	 {
	 	int len;
	 	scanf("%d",&len);
	 	double tmw=(double)len/1.2;
	 	double tmb=(double)len/3.0+27.0+23.0;
	 	if(tmw<tmb) printf("Walk\n");
	 	 else
	 	  if(tmw>tmb) printf("Bike\n");
	 	   else printf("All\n");
	 }
	return 0;
}

5:点和正方形的关系

#include<cstdio>
using namespace std;
int main()
{
	int x,y;
	while(scanf("%d%d",&x,&y)==2)
	 {
	 	if(x>=-1&&x<=1&&y>=-1&&y<=1) printf("yes\n");
	 	 else printf("no\n");
	 }
	return 0;
}

6:数组逆序重放

#include<cstdio>
using namespace std;
int a[110],n;
int main()
{
 int i;
 scanf("%d",&n);
 for (i=1;i<=n;i++)
  scanf("%d",&a[i]);
 for (i=n;i>0;i--)
  printf("%d ",a[i]);
 return 0;
}

7:整数的个数

#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int t1=0,t2=0,t3=0;
	for(int i=1;i<=n;++i)
	 {
	 	int x;
	 	scanf("%d",&x);
	 	if(x==1) t1++;
	 	if(x==5) t2++;
	 	if(x==10) t3++;
	 }
	printf("%d\n%d\n%d\n",t1,t2,t3);
	return 0;
}

8:1的个数

#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	 {
	 	int x,tot=0;
	 	scanf("%d",&x);
	 	while(x)
	 	 {
	 	 	if(x%2) tot++;
	 	 	x/=2;
		  }
		printf("%d\n",tot);
	 }
	return 0;
}








posted @ 2016-10-20 22:00  lris0-0  阅读(124)  评论(0编辑  收藏  举报
过去的终会化为美满的财富~o( =∩ω∩= )m