【openjudge 计算概论(A)】[基础编程练习2]
来源:互联网 发布:gta5fps优化 编辑:程序博客网 时间:2024/04/30 10:39
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;}
0 0
- 【openjudge 计算概论(A)】[基础编程练习2]
- 【openjudge 计算概论(A)】[基础编程练习1]
- 【openjudge 计算概论(A)】[编程练习(数组练习)]
- 【openjudge 计算概论(A)】[编程练习(字符串)]
- 【openjudge 计算概论(A)】[基础编程练习(控制成分)]
- 【openjudge 计算概论(A)】[基础编程练习(运算成分)]
- 【openjudge 计算概论(A)】[基础编程练习(数据成分)]
- openjudge 计算概论基础编程练习(控制成分)
- 【openjudge 计算概论(A)】[指针练习]
- 【openjudge 计算概论(A)】[函数递归练习(2)]
- 【openjudge 计算概论(A)】[函数递归练习(4)]
- 【openjudge 计算概论(A)】[函数递归练习(3)]
- 【openjudge 计算概论(A)】[函数递归练习(1)]
- 【openjudge 计算概论(A)】[ 函数与字符串练习(2)]
- 【openjudge 计算概论(A)】[函数与字符串练习(1)]
- 【openjudge 计算概论(A)】[结构体与链表练习]
- openjudge 计算概论 函数与字符串练习(1)2:字符串排序
- openjudge 计算概论-数组练习-错误侦测
- JAVA编程基础(四)开启Java语言编程之旅
- NOIP2012Vigenère密码
- lua解析csv,插入到数据库
- Download dataset from mainframe on a linux
- 使用原子主机、Ansible 和 Cockpit 部署容器
- 【openjudge 计算概论(A)】[基础编程练习2]
- 【12.78%】【codeforces 677D】Vanya and Treasure
- iOS 多线程编程<十二、NSOperation线程间通信>
- 启动进程:exec簇函数
- DynamicProgramming——矩阵连乘
- 字符串函数
- CNCC2016 中国计算机大会 与会感想
- HTML基础笔记之框架标签(现在不使用了)
- HashMap学习笔记