笔试题 门禁打卡

凑出结果。。。。

/*
第一题
题目:智慧打卡系统
某家高科技公司为方便员工省去每日上下班的打卡操作,计划推广使用智慧打卡系统。
其运行的原理是系统会记录员工当日进出门禁的时间
(员工在上班期间可能会多次进出门禁,格式为24小时制,小时:分钟,“HH:MM”)。
现在请编写一个算法,计算员工当日的工作时长(单位:分钟),具体要求如下:
1、单次离岗15min以内,不从工作时长中扣除。
2、12 : 00至14 : 00为午休时间,不算工作时长。
3、18 : 00至19 : 30为晚饭时间,不算工作明长。
解答要求
时间限制 : C / C++1000ms其他语言 : 2000ms内存限制 : C / C++256MB其他语言 : 512MB
输入描述
第一行 : 员工当天进门禁的次数n。
第二行 : 员工当天进门禁的所有时间,以空格分隔。
第三行 : 员工当天出门禁的次数m。
第四行 : 员工当天出门禁的所有时间,以空格分隔。
注 : 0 < n, m < 100,不存在相同的出入门禁时间,也不存在连续的出门禁或入门禁的情况。
	输出描述
	当日的工作时长。
	样例输入
	示例一:
	5
	07:50 08:50 12:30 13:40 19:50
	7:50 8:50 12:30 13:40 19:50
	5
	08:45 12:20 13:20 18:30 20:30
	8:45 12:20 13:20 18:30 20:30
	示例二:
	4
	08 : 30 12 : 30 14 : 00 18 : 20
	4
	12 : 00 13 : 00 16 : 50 19 : 00
	样例输出
	530
	解释:员工的工作时段为07 : 50 - 12 : 00, 14 : 00~18 : 00, 19 : 50~20 : 30,工作时长为530分钟
	示例二:
	380
	解释员工的工作时段为08 : 30~12 : 00, 14 : 00~16 : 50,工作时长为380分钟
*/
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;

//每次传入一个入门时间与一个出门时间
//返回工作时长
int last_in_h=0, last_in_m=0,last_ou_h=0, last_ou_m = 0;
int dispose_time(string input_door, string output_door)
{
	string in_h, in_m;
	int in_ht, in_mt;
	stringstream s1(input_door);
	getline(s1, in_h, ':');
	//cout << in_h;
	getline(s1, in_m, ':');
	//cout << in_m;
	in_ht = stoi(in_h);
	in_mt = stoi(in_m);

	stringstream  s2(output_door);
	string ou_h, ou_m;
	int ou_ht, ou_mt;
	getline(s2, ou_h, ':');
//	cout << ou_h;
	getline(s2, ou_m, ':');
	//cout << ou_m;
	ou_ht = stoi(ou_h);
	ou_mt = stoi(ou_m);
//	cout << "入门时:" << in_ht << "入门分:" << in_mt << endl;
//	cout << "出门时:" << ou_ht << "出门分:" << ou_mt << endl;

	int alltime = 0;
	if (in_ht >= 12 && ou_ht <= 14 || in_ht >= 18 && ou_ht <= 19)
	{
		alltime = 0;
		cout << "此次为0" << endl;
		return 0;
	}
	if (in_ht >= 12 && in_ht < 14) in_ht = 14, in_mt = 0;
	if (in_ht >= 18 && in_ht < 19) in_ht = 19, in_mt = 0;
	if (ou_ht >= 12 && ou_ht < 14) ou_ht = 12, ou_mt = 0;
	if (ou_ht >= 18 && ou_ht < 19) ou_ht = 18, ou_mt = 0;
	alltime = (ou_ht - in_ht) * 60 + (ou_mt - in_mt);
	//cout << alltime;
	//还要计算低于15分钟不扣
	if (last_in_h != 0)
	{
		int time = (in_ht - last_ou_h) * 60 + (in_mt - last_ou_m);
		if (time <= 15)
		{
			alltime += time;
		}

	}
	cout << "此次工作时长为:" << alltime<<endl;
	//记录上一次时间
	last_in_h = in_ht;
	last_in_m = in_mt;
	last_ou_h = ou_ht;
	last_ou_m = ou_mt;
	return alltime;
}



int main()
{
	int n1;
	cout << "输入入门次数:";
	cin >> n1; //入门次数
	cin.ignore();//清除输入缓存\n
	cout << "输入每次入门时间:";
	string s1;
	getline(cin, s1);  //需要输入两次回车结束,vc bug
	cin.ignore();
	//cout << s1;
	//分割字符串存入vector数组
	vector<string> str1;
	istringstream ss(s1);
	string time;
	while (getline(ss, time, ' '))
	{
		str1.push_back(time);
	}
	// 输出分割后的时间字符串
	//for (const std::string& t : str1) {
	//	std::cout << t << std::endl;
	//}
	for (int i = 0; i < n1; i++)
	{
		cout << "第" << i << "次入门时间为" << str1[i] << endl;
	}
	/*int end = s1.size()-1;
	int start = 0;
	for (int i = 0; i <= s1.size()-1; i++)
	{
		if (i==end||s1[i] == ' ')
		{  
			string time = s1.substr(start, i - start + 1);
			
			start = i + 1;
		}
	}*/


	int n2;
	cout << "输入出门次数:";
	cin >> n2;//出门次数
	cin.ignore();
	cout << "输入每次出门时间:";
	string s2;
	getline(cin, s2);
	cout << s2;
	vector<string> str2;
	istringstream ss2(s2);
	string time2;
	while (getline(ss2, time2, ' '))
	{
		str2.push_back(time2);
	}
	for (int i = 0; i < n1; i++)
	{
		cout << "第" << i << "次入门时间为" << str2[i] << endl;
	}

	cout << "测试输出:" << endl;
	int alltime = 0;
	for (int i = 0; i < n1; i++)
	{
		alltime += dispose_time(str1[i],str2[i]);
	}
	
	cout <<"总共时间为: "<< alltime;

	system("pause");
	return 0;
}

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值