Codeforces Round #419 A

本文介绍了一种通过编程解决问题的方法,即找到当前时间之后最近的一个回文时间。使用C++实现,通过调整分钟数来寻找满足条件的时间点,并讨论了暴力搜索策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Karen and Morning

题意:给你一个时间,求最少多少分钟后,表示时间的字符串是一个回文串,时间是24小时制,但是24:00 表示为00:00

思路:暴力最多一天就一定会出现回文,所以最多24*60*60   xjb写就可以了

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int N=2e5+100;
int a,b,c,d;
int check(){
    if((b/10)==d && (b%10)==c)
        return 1;
    return 0;
}
int main(){
    char s;
    int ans=0;
    cin>>b>>s>>c;
    d=c%10;
    c=c/10;
    if(check()){
        cout<<ans<<endl;
        return 0;
    }
    while(!check()){
        ans++;
        d+=1;
        if(d>=10){
            c++;
            d=0;
        }
        if(c>=6){
            b++;
            c=0;
        }
        if(b>=24){
            b=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/max88888888/p/7091826.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值