洛谷 题解 P1615 【西游记公司】

我的程序只有1行。。。

return scanf("%d:%d:%d\n%d:%d:%d\n%d", &a, &b, &c, &x, &y, &z, &t), printf("%d", ((x - a) * hs + (y - b) * ms + (z - c) * ss) * t) % 1;

两句改中间的';'为','

%%%

主程序

#include <stdio.h> //标准的纯C式代码
#define hs 3600    //精髓!hs:Hours to Seconds
#define ms 60	   //ms:Minutes to Seconds
#define ss 1	   //ss:Seconds to Seconds(白说了一样,这句没有用。。。)
int a, b, c, x, y, z, t;

int main()
{
	return scanf("%d:%d:%d\n%d:%d:%d\n%d", &a, &b, &c, &x, &y, &z, &t), printf("%d", ((x - a) * hs + (y - b) * ms + (z - c) * ss) * t) % 1; //注意"%1"。无论什么数,%1后都是0,程序正常返回。。。
}

看到scanf("%d:%d:%d\n%d:%d:%d\n%d", &a, &b, &c, &x, &y, &z, &t),这是一个精髓,scanf中的“非%式”字母,都是要真实读入的!

posted @ 2018-11-02 14:01  航空信奥  阅读(234)  评论(0编辑  收藏  举报