链接:https://ac.nowcoder.com/acm/contest/5667/D
来源:牛客网
题目描述:
Given two moments on the same day in the form of HH:MM:SS, print the number of seconds between the two moments.
输入描述:
Input two lines each contains a string in the form of HH:MM:SS (00≤HH≤23,00≤MM,SS≤59), denoting a given moment.
输出描述:
Only one line containing one integer, denoting the answer.
solution:
将时间全部化成秒,然后两个时间相减,取绝对值
#include <iostream> #include<stdio.h> #include<string> #include<string.h> #include<map> #include<queue> #include<vector> #include<algorithm> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; typedef pair<int,int>P; int h1,h2,m1,m2,s1,s2; int main() { scanf("%d:%d:%d",&h1,&m1,&s1); scanf("%d:%d:%d",&h2,&m2,&s2); int h,m,s; h=h1-h2; m=m1-m2; s=s1-s2; int ans=h*3600+m*60+s; cout<<abs(ans)<<endl; return 0; }