PAT基础编程题目-7-10 计算工资

PAT基础编程题目-7-10 计算工资

题目详情

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

解答

C语言版

#include<stdio.h>
int main()
{
   
	int age, time;
	float wage;
	scanf("%d %d", &age, &time);
	if (age < 5) {
     //新员工
		if (time<=40)
			wage = 30 * time;
		else
			wage = 30 * 40 + 30 * 1.5 * (time - 40);
	}
	else {
     // 老员工
		if (time <= 40)
			wage = 50 * time;
		else 
			wage = 50 * 40 + 50 * 1.5 * (time - 40);
	}
	printf("%.2f", wage);
	return 0;
}

C++版

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
   
	int age, time;
	float wage;
	cin >> age >> time;
	if (age < 5) {
     //新员工
		if (time <= 40)
			wage = 30 * time;
		else
			wage = 30 * 40 + 30 * 1.5 * (time - 40);
	}
	else {
     // 老员工
		if (time <= 40)
			wage = 50 * time;
		else
			wage = 50 * 40 + 50 * 1.5 * (time - 40);
	}
	cout << fixed << setprecision(2) << wage;
	return 0;
}

Java版

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main{
   

	public static void main(String[] args) {
   
		int age = 0,time = 0;
		float wage;
		Scanner scanner = new Scanner(System.in);
		if (scanner.hasNext()) {
   
			age = scanner.nextInt();
			time = scanner.nextInt();
		}
		scanner.close();
		if (age < 5) {
     //新员工
			if (time <= 40)
				wage = 30 * time;
			else
				wage = (float) (30 * 40 + 30 * 1.5 * (time - 40));
		}
		else {
     // 老员工
			if (time <= 40)
				wage = 50 * time;
			else
				wage = (float) (50 * 40 + 50 * 1.5 * (time - 40));
		}
		DecimalFormat decimalFormat = new DecimalFormat("#.00");
		System.out.println(decimalFormat.format(wage));

	}

}

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

全部评论

相关推荐

爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务