Skip to content

Commit ffddcf9

Browse files
committed
update
1 parent c8d6990 commit ffddcf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1565
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
点评赛车
3+
4+
描述
5+
6+
4名专家对4款赛车进行评论
7+
8+
1)A说:2号赛车是最好的;
9+
10+
2)B说:4号赛车是最好的;
11+
12+
3)C说:3号赛车不是最好的;
13+
14+
4)D说: B说错了。
15+
16+
事实上只有1款赛车最佳,且只有1名专家说对了,其他3人都说错了。
17+
18+
请编程输出最佳车的车号,以及说对的专家。
19+
20+
输入
21+
22+
无输入。
23+
24+
输出
25+
26+
输出两行。第一行输出最佳车的车号(1-4中的某个数字)。第二行输出说对的专家(A-D中的某个字母)。
27+
*/
28+
#include <iostream>
29+
using namespace std;
30+
31+
int main()
32+
{
33+
for (int best = 1; best <= 4; best++)
34+
{
35+
bool a = (best == 2);
36+
bool b = (best == 4);
37+
bool c = (best != 3);
38+
bool d = !b;
39+
// 只有一个专家说对
40+
if (a + b + c + d == 1)
41+
{
42+
cout << best << endl;
43+
if (a)
44+
{
45+
cout << "A" << endl;
46+
}
47+
else if (b)
48+
{
49+
cout << "B" << endl;
50+
}
51+
else if (c)
52+
{
53+
cout << "C" << endl;
54+
}
55+
else if (d)
56+
{
57+
cout << "D" << endl;
58+
}
59+
}
60+
}
61+
return 0;
62+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int k;
7+
cin >> k;
8+
int n1 = 0, n5 = 0, n10 = 0;
9+
for (int i = 0; i < k; i++)
10+
{
11+
int n;
12+
cin >> n;
13+
switch (n)
14+
{
15+
case 1:
16+
n1++;
17+
break;
18+
case 5:
19+
n5++;
20+
break;
21+
case 10:
22+
n10++;
23+
break;
24+
}
25+
}
26+
cout << n1 << endl;
27+
cout << n5 << endl;
28+
cout << n10 << endl;
29+
return 0;
30+
}
31+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
9+
for (int i = 0; i < n; i++)
10+
{
11+
int x, ans = 0;
12+
cin >> x;
13+
while (x > 0)
14+
{
15+
ans += x % 2;
16+
x /= 2;
17+
}
18+
cout << ans << endl;
19+
}
20+
return 0;
21+
}
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
int a[100];
8+
cin >> n;
9+
10+
for (int i = 0; i < n; i++)
11+
{
12+
int x = 0;
13+
cin >> x;
14+
a[n - i - 1] = x;
15+
}
16+
17+
for (int i = 0; i < n; i++)
18+
{
19+
cout << a[i] << ' ';
20+
}
21+
return 0;
22+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
6+
7+
int main()
8+
{
9+
int n; //细菌数量
10+
int id[100];
11+
double rate[100];
12+
13+
cin >> n;
14+
for (int i = 0; i < n; i++)
15+
{
16+
int x1, x2;
17+
cin >> id[i] >> x1 >> x2;
18+
rate[i] = (x2 - x1) / x1;
19+
}
20+
21+
// 根据繁殖率排序
22+
for (int i = 0; i < n; i++)
23+
{
24+
for (int j = 0; j < n - i - 1; j++)
25+
{
26+
if (rate[j + 1] > rate[j])
27+
{
28+
int tmpId = id[j];
29+
id[j] = id[j + 1];
30+
id[j + 1] = tmpId;
31+
double tmpRate = rate[j];
32+
rate[j] = rate[j + 1];
33+
rate[j + 1] = tmpRate;
34+
}
35+
}
36+
}
37+
38+
double maxDiff = 0;
39+
int maxDiffIndex = 0;
40+
for (int i = 0; i < n - 1; i++)
41+
{
42+
double diff = rate[i] - rate[i + 1];
43+
if (maxDiff < diff)
44+
{
45+
maxDiff = diff;
46+
maxDiffIndex = i;
47+
}
48+
}
49+
50+
// 输出A亚种细菌
51+
cout << maxDiffIndex + 1 << endl;
52+
for (int i = maxDiffIndex; i >= 0; i--)
53+
{
54+
cout << id[i] << endl;
55+
}
56+
57+
// 输出B亚种细菌
58+
cout << n - maxDiffIndex - 1 << endl;
59+
for (int i = n - 1; i > maxDiffIndex; i--)
60+
{
61+
cout << id[i] << endl;
62+
}
63+
64+
return 0;
65+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
描述
3+
4+
你买了一箱n个苹果,很不幸的是买完时箱子里混进了一条虫子。虫子每x小时能吃掉一个苹果,假设虫子在吃完一个苹果之前不会吃另一个,那么经过y小时你还有多少个完整的苹果?
5+
6+
输入
7+
8+
输入仅一行,包括n,x和y(均为整数)。
9+
10+
输出
11+
12+
输出也仅一行,剩下的苹果个数
13+
*/
14+
15+
#include <iostream>
16+
using namespace std;
17+
18+
int main()
19+
{
20+
int n = 0;
21+
double x = 0, y = 0;
22+
cin >> n >> x >> y;
23+
int ans = n - y / x;
24+
ans = ans < 0 ? 0 : ans;
25+
cout << ans << endl;
26+
return 0;
27+
}
1020 KB
Binary file not shown.
1.48 KB
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
大象喝水
3+
4+
描述
5+
6+
一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数)。问大象至少要喝多少桶水才会解渴。
7+
8+
输入
9+
10+
输入有一行:包行两个整数,以一个空格分开,分别表示小圆桶的深h和底面半径r,单位都是厘米。
11+
12+
输出
13+
14+
输出一行,包含一个整数,表示大象至少要喝水的桶数。
15+
*/
16+
17+
#include <iostream>
18+
#include <math.h>
19+
using namespace std;
20+
21+
int main()
22+
{
23+
int h = 0, r = 0;
24+
cin >> h >> r;
25+
float pi = 3.14159;
26+
double v = pi * r * r * h;
27+
int ans = ceil(20000 / v);
28+
cout << ans << endl;
29+
return 0;
30+
}
31+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
最高的分数
3+
4+
描述
5+
6+
孙老师讲授的《计算概论》这门课期中考试刚刚结束,他想知道考试中取得的最高分数。因为人数比较多,他觉得这件事情交给计算机来做比较方便。你能帮孙老师解决这个问题吗?
7+
8+
输入
9+
10+
输入两行,第一行为整数n(1 <= n < 100),表示参加这次考试的人数.第二行是这n个学生的成绩,相邻两个数之间用单个空格隔开。所有成绩均为0到100之间的整数。
11+
12+
输出
13+
14+
输出一个整数,即最高的成绩。
15+
*/
16+
17+
#include <iostream>
18+
using namespace std;
19+
20+
int main()
21+
{
22+
int score = 0;
23+
int n = 0;
24+
cin >> n;
25+
26+
int max = 0;
27+
for (int i = 0; i < n; i++)
28+
{
29+
cin >> score;
30+
if (score > max)
31+
{
32+
max = score;
33+
}
34+
}
35+
cout << max << endl;
36+
return 0;
37+
}

0 commit comments

Comments
 (0)