B.实习生的工资

版权声明:晓程原创 https://blog.csdn.net/qq_43469554/article/details/88097631

某公司的实习生工资按照出勤天数计算,干一天活给一天钱。并且每个月最多只计算21.5天的出勤,也就是如果从月头到月尾出勤超过了21.5天也只会按照21.5计算。
小红2019年2月11日(周一) 入职了该公司(算一天出勤),她打算实习一年,也就是2020年2月11日当天离职(离职当天不会算出勤)。并且她周六和周日不想上班,周一到周五每天都可以上班。那么她这一年一共最多能有多少天的出勤。

answer:253.5

#include <iostream> 
using namespace std;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
	int y = 2019, m = 2, d = 11, w = 1;
	double sum = 0;
	int cnt = 0;
	while (1)
	{
		if (y == 2020 && m == 2 && d == 11)
		{
			sum += min (cnt * 1.0, 21.5);
			break;
		}
		if (w != 7 && w != 6)
		{
			cnt++;
		}
		d++;
		w++;
		if (w > 7)
		{
			w= 1;
		}
		if (d > month[m])
		{
			sum += min(1.0 * cnt, 21.5);
			cnt = 0;
			d = 1;
			m++; 
		}
		if (m > 12)
		{
			m = 1;
			y++;
		}
	}
	cout << sum << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43469554/article/details/88097631