You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
/*
第一个的文字:小A的寝室里放着一个时钟。时钟有时针,分针,秒针三种指针。在某些时刻,时钟会记录下当前时间,格式为hh:mm:ss。 时钟上看不出日期,每天零点,三根指针都会归零。现在小A得到了一系列被记录的时间,且这些时间是按照先后顺序被记录的。 小A想让你算算,每两个时间点之间,秒针至少转了多少圈。注:一天有 24 个小时,1 小时有 60 分钟,1分钟有 60 秒,秒针一分钟转一圈。 输入描述:第一行一个整数 n(2 ≤n < 10e5),代表时间序列中时间点的个数。第二行n个字符串,每个字符串代表一个时间点,格式为hh:mm:ss(0 ≤ hh< 24, 0≤ mm< 60, 0 ≤ ss < 60). 输出描述:n -1个数,第i个数表示第i到i十1时间点秒针转过的圈数。输出结果和答案的绝对误差或相对误差不超过 10e-5 即被认为正确。
*/ #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std; // Helper function to convert time in "hh:mm:ss" format to total seconds from midnight
int timeToSeconds(const string& time) { int hh = stoi(time.substr(0, 2)); int mm = stoi(time.substr(3, 2)); int ss = stoi(time.substr(6, 2)); return hh * 3600 + mm * 60 + ss; } int main() { int n; cin >> n; vector<string> times(n);
// Input all time points
for (int i = 0; i < n; ++i) { cin >> times[i]; } // Calculate and print the number of full rotations of the second hand between consecutive time points
for (int i = 1; i < n; ++i) { int t1 = timeToSeconds(times[i - 1]); int t2 = timeToSeconds(times[i]);
// If t2 is smaller, it means the time passed to the next day
if (t2 < t1) { t2 += 24 * 3600; // add 24 hours in seconds
} int secondsDiff = t2 - t1; double rotations = secondsDiff / 60.0; // calculate the full rotations
printf("%.*f", 10, rotations); // cout << setprecision(10) << rotations << endl; // print the result
} return 0; }
|