1. 程式人生 > >[Codeforces 816A]Karen and Morning

[Codeforces 816A]Karen and Morning

++ puts font urn cst cpp sca pri -s

題目大意:給你一個時間(hh:mm),求最少經過多少分鐘才能使這個時間變成回文。

解題思路:模擬,先判斷0的情況,然後每過1分鐘判斷一次即可。

C++ Code:

#include<cstdio>
int main(){
	int h,m;
	scanf("%d:%d",&h,&m);
	if(h==m%10*10+m/10){
		puts("0");
		return 0;
	}
	for(int i=1;;++i){
		++m;
		if(m==60){
			m=0;
			++h;
			if(h==24)h=0;
		}
		if(h==m%10*10+m/10){
			printf("%d\n",i);
			return 0;
		}
	}
}

[Codeforces 816A]Karen and Morning