算法竞赛与入门经典 (第一章)
2016-08-03 16:06
330 查看
1-1:平均数
输入3个整数,输出他们的平均值,保留三位小数;
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("%.3lf",(a+b+c)*1.0/3); return 0; }
1-2:温度
输入华氏温度发,输出对应的摄氏温度c,保留3位小数。提示:c=5(f-32)/9;
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int f; scanf("%d",&f); printf("%.3lf",5.0*(f-32)/9); return 0; }
1-3:连续和
输入正整数n,输出 1+2 +.....+ n的值。
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int n,sum=0; scanf("%d",&n); for(int i=1;i<=n;i++) sum+=i; printf("%d\n",sum); return 0; }
1-4:正弦和余弦
输入正整数(n<360),输出n度的正弦,余弦函数值。
<pre name="code" class="csharp">#include<stdio.h> #include<math.h> #define pi 3.1415926 int main() { double n; scanf("%lf", &n); n=(n/180.0)*pi; printf("%lf %lf\n", sin(n), cos(n)); return 0; }1-5:距离
输入4个浮点数x1,y1,x2,y2,输出平面坐标系中点(x1,y1<span style="font-family: Arial, Helvetica, sans-serif;">)到点(x2,y2)的距离</span>
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { double x1,y1,x2,y2,dis,m,n; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); m=x1-x2; n=y1-y2; dis=sqrt(m*m+n*n); printf("%lf",dis); return 0; }
1-6:偶数
输入一个整数,判断它是否为偶数。如果是,则输入“yes”,否则输出“no”。
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; scanf("%d",&n); if(n%2==0) printf("yes\n"); else printf("no\n"); return 0; }1-7:打折
一件衣服95元,若消费满300元,可打85折。输入购买衣服件数,输出需要支付的金额(单位:元),保留两位小数。
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; scanf("%d",&n); if(n*95>=300) printf("%.2lf\n",n*95*0.85); else printf("%d\n",n*95); return 0; }1-8:绝对值
输入一个浮点数,输出他的绝对值,保留两位小数。
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { double a; scanf("%lf",&a); printf("%.2lf",fabs(a)); return 0; }1-9:三角形
输入三角形三边长度值(均为正整数),判断他是否能为直角三角形的两个边长 <pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { int a[3]; memset(a,0,sizeof(a)); for(int i=0;i<3;i++) scanf("%d",&a[i]); sort(a,a+3); if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1]) printf("yes"); else printf("no"); return 0; }1-10:年份
输入年份,判断是否为闰年。如果是,则输出“yes”,否则输出“no”。
<pre name="code" class="csharp">#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { int a,flag; scanf("%d",&a); if(a%400==0) flag=1; else { if(a%4==0&&a%100!=0) flag=1; else flag=0; } if(flag) printf("yes\n"); else printf("no\n"); return 0; }
相关文章推荐
- 算法竞赛入门经典第二版第一章语言篇
- {算法竞赛入门经典}第一章 程序设计入门
- 算法竞赛入门经典第一章习题解答
- 算法竞赛入门经典 第一章的练习题
- 算法竞赛入门经典第二版第一章语言篇
- 【算法竞赛入门经典】【第一章】课后习题
- 算法竞赛入门经典课后习题答案:第一章(C++解法)
- 算法竞赛入门经典 第二章 上机练习(C++代码)
- 算法竞赛入门经典 3.2 字符数组
- 20100617--算法竞赛入门经典 语言篇读书笔记
- 算法竞赛入门经典 例题9-1
- 算法竞赛入门经典 2.1 for 循环
- {算法竞赛入门经典}第二章 文件操作 重定向及fopen版本
- 算法竞赛入门经典 2.1 for 循环
- 算法竞赛入门经典 3.2 字符数组
- 算法竞赛入门经典2-10 用1,2,3,4,5,6,7,8,9组成3个三位数 abc:def:ghi=1:2:3
- 算法竞赛入门经典 7.5.3 八数码问题
- 算法竞赛入门经典 1.1 算术表达式
- 算法竞赛入门经典 3.3 最长回文子串
- 算法竞赛入门经典 例题7-3 倒水问题