杭电 2011 年计算机复试真题

写在前面

此题目是根据 CSDN 博客粥粥同学发布的内容进行收集整理,记录了本人的解题过程和一些想法。仅供大家参考,如有错误,欢迎大家指出!


第一题

Problem Description

给定三条边,请你判断一下能不能组成一个三角形。

Input

输入数据第一行包含一个数 M,接下有 M 行,每行一个实例,包含三个正数 A,B,C。其中 A,B,C <1000;

Output

对于每个测试实例,如果三条边长 A,B,C 能组成三角形的话,输出 YES,否则 NO。

Sample Input

2
1 2 3
2 2 2

Sample Output

NO
YES

解题思路

需要满足条件 a + b > c && a + c > b && b + c > a

参考源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main() {
int n;
double a, b, c;
cin >> n;
while (n--) {
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
return 0;
}

第二题

Problem Description

有个人从 2003 年 1 月 1 日开始,三天打鱼两天晒网,请输入月份、日期,问在当年的某一天他是在打鱼还是在晒网

Input

输入月份、日期

Output

输出当前日期是在打鱼还是晒网,每组输出占一行

Sample Input

1 5

Sample Output

晒网

解题思路

只是当年的计算,不是跨年,比较简单,如果跨年的话,还要判断润平年,然后计算天数,基本方法都是一样的,对 5 取余即可

参考源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main() {
int m, d, days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
while (cin >> m >> d) {
for (int i = 0; i < m - 1; i++) {
d += days[i];
}
if (d % 5 == 0 || d % 5 == 4)
cout << "晒网" << endl;
else
cout << "打鱼" << endl;
}
return 0;
}

第三题

Problem Description

丑数是这样定义的:如果一个正整数的素因子只包含 2、3、5、7 四种,则它被称为丑数。以下数列 1, 2, 3,4, 5,6,7,8,9, 10,12,14,15,16,18, 20, 21,24,25, 27………. 就显示了前 20 个丑数。给出一个正整数 N,判断这个数是否为丑数

Input

输入一个正整数,有多组数据,每组数据占一行

Output

输出当前数字是否为丑数,若是则输出 “Yes” 否则输出 “No”,每组输出占一行

Sample Input

15
26
140

Sample Output

Yes
No
No

解题思路

只要判断能否被 2,3,5,7 整除即可

参考源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
bool isugly(int a) {
while (a % 2 == 0) a /= 2;
while (a % 3 == 0) a /= 3;
while (a % 5 == 0) a /= 5;
while (a % 7 == 0) a /= 7;
if (a == 1)
return true;
else
return false;
}
int main() {
int n;
while (cin >> n) {
if (isugly(n))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}

相关内容