1006 Sign In and Sign Out (25)(25 point(s))
2024-10-02 10:22:35
problem
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.
Input Specification:
Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:
ID_number Sign_in_time Sign_out_time
where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.
Output Specification:
For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.
Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.
Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output:
SC3021234 CS301133
tip
anwser
#include <bits/stdc++.h>
using namespace std;
string firstName, lastName, firstTime, lastTime;
bool CompTime(int a1, int b1, int c1, int a2, int b2, int c2){
if (a1 == a2){
if(b1 == b2)
return c1 < c2;
else return b1 < b2;
}else return a1 < a2;
}
bool CalTime(string timeA, string timeB){
int a1, a2, b1, b2, c1, c2;
int tt;
a1 = (timeA[0]-48)*10 + timeA[1]-48;
a2 = (timeB[0]-48)*10 + timeB[1]-48;
b1 = (timeA[3]-48)*10 + timeA[4]-48;
b2 = (timeB[3]-48)*10 + timeB[4]-48;
c1 = (timeA[6]-48)*10 + timeA[7]-48;
c2 = (timeA[6]-48)*10 + timeA[7]-48;
return CompTime(a1, b1, c1, a2, b2, c2);
}
int main()
{
// freopen("test.txt", "r", stdin);
int N;
cin>>N;
string x, y, z;
for(int i = 0; i < N; i++){
cin>>x>>y>>z;
// cout<<x<<y<<z<<endl;
if(i == 0) {
firstName = lastName = x;
firstTime = y;
lastTime = z;
}else{
if(CalTime(y, firstTime)){
firstTime = y;
firstName = x;
}
if(CalTime(lastTime, z)){
lastTime = z;
lastName = x;
}
}
}
cout<<firstName<<" "<<lastName;
return 0;
}
/*
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
*/
experience
string 函数 :
// string::find_first_of
#include <iostream> // std::cout
#include <string> // std::string
#include <cstddef> // std::size_t
int main ()
{
std::string str ("Please, replace the vowels in this sentence by asterisks.");
std::size_t found = str.find_first_of("aeiou");
while (found!=std::string::npos)
{
str[found]='*';
found=str.find_first_of("aeiou",found+1);
}
std::cout << str << '\n';
return 0;
}
// string::find
#include <iostream> // std::cout
#include <string> // std::string
int main ()
{
std::string str ("There are two needles in this haystack with needles.");
std::string str2 ("needle");
// different member versions of find in the same order as above:
std::size_t found = str.find(str2);
if (found!=std::string::npos)
std::cout << "first 'needle' found at: " << found << '\n';
found=str.find("needles are small",found+1,6);
if (found!=std::string::npos)
std::cout << "second 'needle' found at: " << found << '\n';
found=str.find("haystack");
if (found!=std::string::npos)
std::cout << "'haystack' also found at: " << found << '\n';
found=str.find('.');
if (found!=std::string::npos)
std::cout << "Period found at: " << found << '\n';
// let's replace the first needle:
str.replace(str.find(str2),str2.length(),"preposition");
std::cout << str << '\n';
return 0;
}
// string::substr
#include <iostream>
#include <string>
int main ()
{
std::string str="We think in generalities, but we live in details.";
// (quoting Alfred N. Whitehead)
std::string str2 = str.substr (3,5); // "think"
std::size_t pos = str.find("live"); // position of "live" in str
std::string str3 = str.substr (pos); // get from "live" to the end
std::cout << str2 << ' ' << str3 << '\n';
return 0;
}
最新文章
- Final Cut Pro X效果插件开发总结
- SVN Working Copy locked ,并且进行clean up也还是不行
- 点云匹配和ICP算法概述
- 典型的检查对float精度理解的代码
- 加载xib文件
- html下select追加元素,IE下错误
- C#利用开源软件ffMpeg截取视频图片
- Unity3d 要点板书
- C程序的存储空间布局
- [置顶] 使用红孩儿工具箱完成基于Cocos2d-x的简单游戏动画界面
- android user如何打开一个版本号root才干
- 将SQL获取的信息传递到Email中
- vcs 下使用system verilog调用c函数
- python邮件SMTP的GUI编程
- Problem B: 大整数的加法运算
- redis资料收集
- zabbix邮件发送3.2.4
- 转 Caffe学习系列(4):激活层(Activiation Layers)及参数
- SAP中的读访问日志Read Access Logging(RAL)
- .NET手记-Autofac进阶(属性和方法注入 Property and Method Injection)