返回题解分享
讨论 / 题解分享/ 帖子详情

日期统计(结果填空) - 题解

#include <bits/stdc++.h>
using namespace std;

string str1="8516346707827689565614010094809128502533";

bool f(string str) {
  int i=0;
  for(char c:str1) {
    if(c==str[i]) ++i;
    if(i>=4) return true;
  }
  return false;
}

int main() {
  /*
    找到第一个2023,然后把2023的3前面所有数删除。
 因为要求不重复!!!最多356!!!
  容易发现,满足第一个2023的日期必定满足第2、3...n个2023的日期(n>1)。
  用双指针查找子序列是2023年的每一天。
    8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4
    0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3
  */
  // 把日期打表
  int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},sum=0;
  for(int i=1;i<=12;i++) {
    for(int j=1;j<=a[i];j++) {
      char c;
      string str2="";
      if(i<10) {
        //
        c='0'+i;
        str2+='0';
        str2+=c;
      }
      else {
        //
        c='0'+i/10;
        str2+=c;
        c='0'+i%10;
        str2+=c;
      }
      if(j<10) {
        //
        c='0'+j;
        str2+='0';
        str2+=c;
      }
      else {
        //
        c='0'+j/10;
        str2+=c;
        c='0'+j%10;
        str2+=c;
      }
      if( f(str2) )
        ++sum;
      // cout<<str2;
      // break;
    }
    // break;
  }
  cout<<sum;
  return 0;
}
0 回复 0 转发 0 喜欢 0 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!