洛谷--分支结构题单

三角函数

题目描述

输入一组勾股数 a , b , c ( a ≠ b ≠ c ) a,b,c(a\neq b\neq c) a,b,ca=b=c,用分数格式输出其较小锐角的正弦值。(要求约分。)

输入格式

一行,包含三个正整数,即勾股数 a , b , c a,b,c a,b,c(无大小顺序)。

输出格式

一行,包含一个分数,即较小锐角的正弦值

样例 #1

样例输入 #1

3 5 4

样例输出 #1

3/5

提示

数据保证: a , b , c a,b,c a,b,c 为正整数且 ∈ [ 1 , 1 0 9 ] \in [1,10^9] [1,109]

这道题很水,但是要注意约分的要求,注意实现的方法
约分的实现方法为先利用辗转相除法来求出最大公因数,然后再用要约分的数再除以最大公因数,就能很好的约分

AC代码实现

#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b);
int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	
	for(int i=0;i<3-1;i++)
		for (int j = i; j < 3; j++)
		{
			if (a[i] > a[j])
				swap(a[i], a[j]);
		}
	cout << a[0]/gcd(a[0], a[2])<<"/"<<a[2]/gcd(a[0],a[2]);
	//cout << a[0] << "/" << a[2];
	/*for (int i = 0; i < 3; i++)
		cout << a[i];*/
	//写到这只有80分,因为要约分,再加个求最大公因数的函数
	//这样结果再除以最大公因数就能约分
	return 0;
}
int gcd(int a, int b)
{//使用辗转相除法
	int tmp = b;
	while (a % b != 0) {
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return tmp;
}

[NOIP2005 普及组] 陶陶摘苹果

题目描述

陶陶家的院子里有一棵苹果树,每到秋天树上就会结出 10 10 10 个苹果。苹果成熟的时候,陶陶就会跑去摘苹果。陶陶有个 30 30 30 厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试。

现在已知 10 10 10 个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹果的数目。假设她碰到苹果,苹果就会掉下来。

输入格式

输入包括两行数据。第一行包含 10 10 10 100 100 100 200 200 200 之间(包括 100 100 100 200 200 200 )的整数(以厘米为单位)分别表示 10 10 10 个苹果到地面的高度,两个相邻的整数之间用一个空格隔开。第二行只包括一个 100 100 100 120 120 120 之间(包含 100 100 100 120 120 120 )的整数(以厘米为单位),表示陶陶把手伸直的时候能够达到的最大高度。

输出格式

输出包括一行,这一行只包含一个整数,表示陶陶能够摘到的苹果的数目。

样例 #1

样例输入 #1

100 200 150 140 129 134 167 198 200 111
110

样例输出 #1

5

提示

【题目来源】

NOIP 2005 普及组第一题

水题,直接模拟就行上代码

AC代码实现

#include <bits/stdc++.h>
using namespace std;
int main() {
	int apple[10];
	for (int i = 0; i < 10; i++) {
		cin >> apple[i];
	}
	int touch,sum=0;
	cin >> touch;
	touch += 30;
	for (int i = 0; i < 10; i++) {
		if (apple[i] <= touch)
			sum++;
	}
	cout << sum;
	return 0;
}

【深基3.习8】三角形分类

题目描述

给出三条线段 a , b , c a,b,c a,b,c 的长度,均是不大于 10000 的整数。打算把这三条线段拼成一个三角形,它可以是什么三角形呢?

  • 如果三条线段不能组成一个三角形,输出Not triangle
  • 如果是直角三角形,输出Right triangle
  • 如果是锐角三角形,输出Acute triangle
  • 如果是钝角三角形,输出Obtuse triangle
  • 如果是等腰三角形,输出Isosceles triangle
  • 如果是等边三角形,输出Equilateral triangle

如果这个三角形符合以上多个条件,请按以上顺序分别输出,并用换行符隔开。

输入格式

输出格式

提示

当两短边的平方和大于一长边的平方,说明是锐角三角形。

当两短边的平方和等于一长边的平方,说明是直角三角形。

当两短边的平方和小于一长边的平方,说明是钝角三角形。

注意这里等腰三角形的判断,等边三角形也是等腰三角形.

80分代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);
	if (a[0] + a[1] <=a[2] ) {
		cout << "Not triangle"<<endl;
		return 0;
	}
	else {

	
	if (a[0] * a[0] + a[1] * a[1] > a[2]*a[2])
		cout << "Acute triangle" << endl;
	if (a[0] * a[0] + a[1] * a[1] == a[2]*a[2])
		cout << "Right triangle" << endl;
	if (a[0] * a[0] + a[1] * a[1] < a[2]*a[2])
		cout << "Obtuse triangle" << endl;
	if (a[0] == a[1])
		cout << "Isosceles triangle" << endl;
	if (a[0] == a[1] == a[2])
		cout << "Equilateral triangle" << endl;
	}
		return 0;
}

这个代码里有两个错误,一个是上面讲的等腰三角的判断,还有一个是等边三角形的判断,不能用连等来判断三条边是否相等,要分开来写

AC代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);
	if (a[0] + a[1] <=a[2] ) {
		cout << "Not triangle"<<endl;
		return 0;
	}
	else {

	
	if (a[0] * a[0] + a[1] * a[1] > a[2]*a[2])
		cout << "Acute triangle" << endl;
	if (a[0] * a[0] + a[1] * a[1] == a[2]*a[2])
		cout << "Right triangle" << endl;
	if (a[0] * a[0] + a[1] * a[1] < a[2]*a[2])
		cout << "Obtuse triangle" << endl;
	if (a[0] == a[1]||a[0]==a[2]||a[1]==a[2])
		cout << "Isosceles triangle" << endl;
	
	if (a[0] == a[1] && a[1] == a[2])
		cout << "Equilateral triangle";
	}
		return 0;
}

[COCI2006-2007#2] ABC

题面翻译

【题目描述】

三个整数分别为 A , B , C A,B,C A,B,C。这三个数字不会按照这样的顺序给你,但它们始终满足条件: A < B < C A < B < C A<B<C。为了看起来更加简洁明了,我们希望你可以按照给定的顺序重新排列它们。

【输入格式】

第一行包含三个正整数 A , B , C A,B,C A,B,C,不一定是按这个顺序。这三个数字都小于或等于 100 100 100。第二行包含三个大写字母 A A A B B B C C C(它们之间没有空格)表示所需的顺序。

【输出格式】

在一行中输出 A A A B B B C C C,用一个 (空格)隔开。

感谢 @smartzzh 提供的翻译

题目描述

You will be given three integers A, B and C. The numbers will not be given in that exact order, but we do know that A is less than B and B less than C.
In order to make for a more pleasant viewing, we want to rearrange them in the given order.

输入格式

The first line contains three positive integers A, B and C, not necessarily in that order. All three numbers will be less than or equal to 100.
The second line contains three uppercase letters ‘A’, ‘B’ and ‘C’ (with no spaces between them) representing the desired order.

输出格式

Output the A, B and C in the desired order on a single line, separated by single spaces.

样例 #1

样例输入 #1

1 5 3
ABC

样例输出 #1

1 3 5

样例 #2

样例输入 #2

6 4 2
CAB

样例输出 #2

6 2 4

刚开始没有思路,后面做着做着就突然有了.最开始我的思想是使用字符来读取ABC,因为他说abc之间没有空格,再判断读取的字符,如果是A这开一个整数数组来记录位置,A记为0,B记为1,C记为2,这样和排序后的数组可以重合,但是在利用一个for循环读取数组时报位置异常,代码大致如下
for (int i = 0; i < 3; i++)
cout << a[c[i]];
后来想想不如直接在判断ABC那里直接输出对应的数字,更加简单,于是AC.

AC代码实现

#include <bits/stdc++.h>
using namespace std;
int main() {
	int a[3],c[3],d;
	string b;
	for (int i = 0; i < 3; i++)
			cin >> a[i];
	cin >> b;
	sort(a, a + 3);
	
	for (int i = 0; i < 3; i++) {
		if (b[i] == 'A')
			cout << a[0]<<' ';
		if (b[i] == 'B')
			cout << a[1] << ' ';

		if (b[i] == 'C')
			cout << a[2]<<' ';

	}
	
	

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值