C++ MyClass Date

#include <cstdio>
#include <iostream>
using namespace std;
const int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int h[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
struct Date
{
  int yy, mm, dd;
  Date(int y, int m, int d) : yy(y), mm(m), dd(d){}
  void print()
  {
    cout << yy << ' ' << mm << ' ' << dd << endl;
  }
  bool leap()
  {
    if ((yy % 4 == 0 && yy % 100 != 0) || (yy % 400 == 0)) return true;
    return false;
  }
  int month_end()
  {
    int x = month[mm];
    if (mm == 2 && leap())
      x++;
    return x;
  }
  void next()
  {
    dd++;
    if (dd > month_end())
    {
      dd = 1;
      mm++;
    }
    if (mm > 12)
    {
      mm = 1;
      yy++;
    }
  }
  int s()
  {
    int a[8];
    int y = yy, m = mm, d = dd;
    for (int i = 0; i < 4; i++)
    {
      a[i] = y % 10;
      y /= 10;
    }
    a[4] = m / 10;
    a[5] = m % 10;
    a[6] = d / 10;
    a[7] = d % 10;
    int ss = 0;
    for (int i = 0; i < 8; i++)
      ss += h[a[i]];
    return ss;
  }
};
void solve()
{
  int d;
  scanf("%d", &d);
  Date today(d / 10000, d % 10000 / 100, d % 100);
//  cout << today.s() << endl;
  int ans = 0;
  int m;
  scanf("%d", &m);
  if (today.s() != m)
  while (today.yy < 3000)
  {
    ans++;
    today.next();
//    today.print();
    if (today.s() == m) break;
  }
  if (today.yy == 3000) ans =-1;
  cout << ans << endl;
}
int main()
{
//  freopen("input.txt", "r", stdin);
  int t = 1;
  scanf("%d", &t);
  for (int i = 0; i < t; i++)
    solve();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值