PAT基础编程题目-7-13 日K蜡烛图

PAT基础编程题目-7-13 日K蜡烛图

题目详情

PAT基础编程题目-7-13 日K蜡烛图_第1张图片

题目地址:https://pintia.cn/problem-sets/14/problems/793

解答

C语言版

#include
int main() {
	float open, high, low, close;
	scanf("%f %f %f %f", &open, &high, &low, &close);
	if (close < open)
		printf("BW-Solid");
	else if (close > open)
		printf("R-Hollow");
	else
		printf("R-Cross");
	if (low < open && low < close && high > open && high > close)
		printf(" with Lower Shadow and Upper Shadow");
	else if (low < open && low < close)
		printf(" with Lower Shadow");
	else if (high > open && high > close)
		printf(" with Upper Shadow");
	return 0;
}

PAT基础编程题目-7-13 日K蜡烛图_第2张图片

C++版

#include
using namespace std;
int main() {
	float open, high, low, close;
	cin >> open >> high >> low >> close;
	if (close < open)
		cout << "BW-Solid";
	else if (close > open)
		cout << "R-Hollow";
	else
		cout<< "R-Cross";
	if (low < open && low < close && high > open&& high > close)
		cout << " with Lower Shadow and Upper Shadow";
	else if (low < open && low < close)
		cout << " with Lower Shadow";
	else if (high > open&& high > close)
		cout << " with Upper Shadow";
	return 0;
}

PAT基础编程题目-7-13 日K蜡烛图_第3张图片

Java版

import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		float open = 0, high = 0, low = 0, close = 0;
		Scanner scanner = new Scanner(System.in);
		if (scanner.hasNext()) {
			open = scanner.nextFloat();
			high = scanner.nextFloat();
			low = scanner.nextFloat();
			close = scanner.nextFloat();
		}
		scanner.close();
		if (close < open)
			System.out.print("BW-Solid");
		else if (close > open)
			System.out.print("R-Hollow");
		else
			System.out.print("R-Cross");
		if (low < open && low < close && high > open&& high > close)
			System.out.print(" with Lower Shadow and Upper Shadow");
		else if (low < open && low < close)
			System.out.print(" with Lower Shadow");
		else if (high > open&& high > close)
			System.out.print(" with Upper Shadow");

	}

}

PAT基础编程题目-7-13 日K蜡烛图_第4张图片

创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!

你可能感兴趣的:(C,C++,Java,PAT,基础编程题)