scanf("%d(+%d)%d", &a, &b, &c);
对于空白字符:空格、tab、回车等,scanf将忽略输入字符串的空白字符,
直到下一个非空白字符,(并回放该非空白字符),
若该非空白字符与格式化字符串匹配,则读入(例如:scanf("%d(+%d)%d", &a, &b, &c) 若输入1(+2)3则可以读入)
若该非空白字符与格式化字符串不匹配,则结束此次读取,
并将该非空白字符回存到缓存中,在下一次读取函数被调用时读取(如scanf、getchar等)
思路
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int h[4], m[4], s[4], f[4],t[4];
int to_second(int h,int m,int s)
{
return h * 3600 + m * 60 + s;
}
void to_date(int s)
{
int m = s / 60; s %= 60;
int h = m / 60; m %= 60;
printf("%02d:%02d:%02d\n", h, m, s);
}
int main()
{
int n; cin >> n;
while (n--)
{
memset(f, 0, sizeof(f));
for (int i = 0; i < 4; i++)
{
scanf("%d:%d:%d (+%d)", &h[i], &m[i], &s[i], &f[i]);//前三个必定会读入,第四个仅当格式为(+t)时才会被读入,否则本次读入结束
if (f[i] == 1)h[i] += 24;
if (f[i] == 2)h[i] += 48;
t[i] = to_second(h[i], m[i], s[i]);
}
to_date(t[1] - t[0] + t[3] - t[2] >> 1);
}
}
为什么我这样输入的时间是不对的啊,错在t11与t22那里,也就是次日或者第三日
scanf(“%d:%d:%d %d:%d:%d (+%d) “,&h1,&m1,&s1,&h11,&m11,&s11,&t11);
int S1=get_s(h1,m1,s1,0);
int S11=get_s(h11,m11,s11,t11);
int x1=S11-S1;
妙啊
妙计
确实妙
66666
太顶了兄弟
老铁666