《算法竞赛入门经典》习题参考代码(第一章)
2015-03-23 10:11
253 查看
//习题1-1 平均数
4000
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int a, b, c, sum;
double avg;
scanf("%d%d%d", &a, &b, &c);
sum = a + b + c;
avg = sum / 3.0;
printf("%.3lf\n",avg);
return 0;
}
//习题1-2 温度
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int f;
double c;
scanf("%d",&f);
c = 5 * (f - 32) / 9.0;
printf("%.3lf\n",c);
return 0;
}
//习题1-3 连续和
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",n * (n + 1) / 2);
return 0;
}
//习题1-4 正弦和余弦
//author by liuchao
//2015-3-17
//360度 = 2PI弧度
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 4.0 * atan(1.0);
int n;
scanf("%d",&n);
printf("%llf %llf\n",sin(PI / 180 * n),cos(PI / 180 * n));
return 0;
}
//习题1-5 打折
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
double sum;
scanf("%d",&n);
sum = n * 95;
if (sum >= 300)
sum = sum * 0.85;
printf("%.2lf\n",sum);
return 0;
}
//习题1-6 三角形
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int a, b, c;
scanf("%d%d%d",&a, &b, &c);
if (( a + b > c) && (b + c > a) && (c + a > b))
{
if((a * a + b * b == c * c) || (b * b + c * c == a * a) || (c * c + a * a == b * b))
printf("yes");
else
printf("no");
}
else
{
printf("not a triangle");
}
}
//习题1-7 闰年
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if (((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0))
printf("yes");
else
printf("no");
return 0;
}
4000
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int a, b, c, sum;
double avg;
scanf("%d%d%d", &a, &b, &c);
sum = a + b + c;
avg = sum / 3.0;
printf("%.3lf\n",avg);
return 0;
}
//习题1-2 温度
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int f;
double c;
scanf("%d",&f);
c = 5 * (f - 32) / 9.0;
printf("%.3lf\n",c);
return 0;
}
//习题1-3 连续和
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",n * (n + 1) / 2);
return 0;
}
//习题1-4 正弦和余弦
//author by liuchao
//2015-3-17
//360度 = 2PI弧度
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 4.0 * atan(1.0);
int n;
scanf("%d",&n);
printf("%llf %llf\n",sin(PI / 180 * n),cos(PI / 180 * n));
return 0;
}
//习题1-5 打折
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
double sum;
scanf("%d",&n);
sum = n * 95;
if (sum >= 300)
sum = sum * 0.85;
printf("%.2lf\n",sum);
return 0;
}
//习题1-6 三角形
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int a, b, c;
scanf("%d%d%d",&a, &b, &c);
if (( a + b > c) && (b + c > a) && (c + a > b))
{
if((a * a + b * b == c * c) || (b * b + c * c == a * a) || (c * c + a * a == b * b))
printf("yes");
else
printf("no");
}
else
{
printf("not a triangle");
}
}
//习题1-7 闰年
//author by liuchao
//2015-3-17
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if (((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0))
printf("yes");
else
printf("no");
return 0;
}
相关文章推荐
- 算法竞赛入门经典 第一章 上机练习(C++代码)
- 算法竞赛入门经典 第一章 上机练习(C++代码)
- JAVA代码—算法竞赛入门经典(第2版)刘汝佳题解—习题3-1 得分
- 自考本科《计算机网络原理》课后习题参考答案(第一章)
- JAVA代码—算法竞赛入门经典(第2版)刘汝佳题解—习题2-2 水仙花数
- JAVA代码—算法竞赛入门经典(第2版)刘汝佳题解—习题2-1 水仙花数
- 计算机程序的构造和解释第一章习题参考答案(DrPacket中编译通过)
- 算法竞赛入门经典第一章习题答案
- 算法竞赛入门经典第一章【小结与习题】
- JAVA代码—算法竞赛入门经典(第2版)刘汝佳题解—习题2-4 子序列的和
- 算法竞赛入门经典(第二版)习题解答参考(第二章)
- 算法竞赛入门经典 第一章 上机练习(C++代码)
- sicp习题答案和范例代码 - 第一章
- 《算法竞赛入门经典》第一章 程序设计入门 习题
- 算法竞赛入门经典习题与解答-第一章
- 算法竞赛入门经典(第二版)第一章课后习题
- 算法竞赛入门经典(第2版)第一章习题(Java)
- 第一章 绪论习题参考答案
- 快学scala 第一章 读书笔记及习题答案代码
- 怎样写C代码——《狂人C》习题解答1(第一章习题7)