题解 | #ranko的手表#
ranko的手表
http://www.nowcoder.com/practice/37275e85ae7c4453920eae6b9f7f45fc
将一天的时间进行以分钟为单位进行转换,并进行从0到24 * 60分钟进行遍历,若分钟用i表示,那么将i进行24小时制进行转换,当至少满足所提供的两个时间其一时,将该时间存入各自的容器中,最后进行遍历两个容器,分别求得最大值与最小值。
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
int total_minute = 24 * 60,mint = 1e+6,maxt = 0;
vector<int> vec1, vec2;
for (int i = 0; i < total_minute; ++i) {
int hour = i / 60, minute = i % 60;
if ((a[0] == '?' || a[0] - '0' == hour / 10) && (a[1] == '?' || a[1] - '0' == hour % 10) && (a[3] == '?' || a[3] - '0' == minute / 10)
&& (a[4] == '?' || a[4] - '0' == minute % 10))
vec1.push_back(i);
if ((b[0] == '?' || b[0] - '0' == hour / 10) && (b[1] == '?' || b[1] - '0' == hour % 10) && (b[3] == '?' || b[3] - '0' == minute / 10)
&& (b[4] == '?' || b[4] - '0' == minute % 10))
vec2.push_back(i);
}
for (int i = 0; i < vec1.size(); ++i) {
for (int j = 0; j < vec2.size(); ++j) {
if (vec1[i] < vec2[j]) {
mint = min(vec2[j] - vec1[i], mint);
maxt = max(vec2[j] - vec1[i], maxt);
}
}
}
cout << mint << " " << maxt;
}