1 条题解
-
0
#include<bits/stdc++.h> using namespace std; int month[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31},top,ans=5,sum;//先把每个月的天数储存,ans代表最终答案,sum代表当前日期需要改变量 string zh(int x) {//将数字转化为string类型 string ans=""; if(x<10) ans="0",ans+=char(x+'0');//如果一位数直接弄 else while(x) {//两位数 ans=char(x%10+'0')+ans; x/=10; } return ans; } string s,p[366]; int main() { cin>>s;//读入题中所给日期 for(register int i=1; i<=12; i++) for(register int j=1;j<=month[i];j++) p[++top]=zh(i)+'-'+zh(j);//将一年的所有日期存入数组p中 for(register int i=1;i<=365;i++){ sum=0;//先清零 for(register int j=0;j<5;j++) if(p[i][j]!=s[j]) sum++;//如果不一样代表这里要改动,sum值+1 ans=min(ans,sum);//求最小值 } printf("%d",ans); }
- 1
信息
- ID
- 4613
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 7
- 已通过
- 3
- 上传者