浙大PTA基础编程题目集:7-10 计算工资

浙大PTA<基础编程题目集>:7-10 计算工资


题目内容
某公司员工的工资计算方法如下:一周内工作时间不超过40小时,按正常工作时间计酬;超出40小时的工作时间部分,按正常工作时间报酬的1.5倍计酬。员工按进公司时间分为新职工和老职工,进公司不少于5年的员工为老职工,5年以下的为新职工。新职工的正常工资为30元/小时,老职工的正常工资为50元/小时。请按该计酬方式计算员工的工资。

输入格式
输入在一行中给出2个正整数,分别为某员工入职年数和周工作时间,其间以空格分隔。

输出格式
在一行输出该员工的周薪,精确到小数点后2位。

输入样例1

5 40

输出样例1

2000.00

输入样例2

3 50

输出样例2

1650.00

代码一:C语言

#include "stdio.h"
int main(){
    int years, times;
    scanf("%d %d",&years,&times);
    if (years >= 5)  //old employee
    {
        if (times <= 40)  printf("%.2f",50.00*times);
        else  printf("%.2f",2000.00+75.00*(times-40));
    }
    else  //new employee
    {
        if (times <= 40)  printf("%.2f",30.00*times);
        else  printf("%.2f",1200.00+45.00*(times-40));
    }
    return 0;
}

代码二:Python

# -*- coding: utf-8 -*-
years, times = map(int, input().split())
if years >= 5:  #old employee
    if times <= 40:
        print("{:.2f}".format(50.00*times))
    else:
        print("{:.2f}".format(2000.00+75.00*(times-40)))
else:  #new employee
    if times <= 40:
        print("{:.2f}".format(30.00*times))
    else:
        print("{:.2f}".format(1200.00+45.00*(times-40)))
发布了16 篇原创文章 · 获赞 0 · 访问量 135

猜你喜欢

转载自blog.csdn.net/niexinyu0026/article/details/104136387