湛江做网站苏州厂商,模板建站优缺点,开源的 二次网站开发,网站文章没有被收录特殊时间
问题描述
本题为填空题#xff0c;只需要算出结果后#xff0c;在代码中使用输出语句将所填结果输出即可。 2022年2月22日22:20 是一个很有意义的时间, 年份为 2022 , 由 3 个 2 和 1 个 0 组成, 如果将月和日写成 4 位, 为 0222 , 也是由 3 个 2 和 1 个 0 组 成…特殊时间
问题描述
本题为填空题只需要算出结果后在代码中使用输出语句将所填结果输出即可。 2022年2月22日22:20 是一个很有意义的时间, 年份为 2022 , 由 3 个 2 和 1 个 0 组成, 如果将月和日写成 4 位, 为 0222 , 也是由 3 个 2 和 1 个 0 组 成, 如果将时间中的时和分写成 4 位, 还是由 3 个 2 和 1 个 0 组成。 小蓝对这样的时间很感兴趣, 他还找到了其它类似的例子, 比如 111 年 10 月 11 日 01112202年2月22日2202等等。 请问, 总共有多少个时间是这种年份写成 4 位、月日写成 4 位、时间写成 4 位后由 3 个一种数字和 1 个另一种数字组成。注意 1111 年 11 月 11 日 11:11 不算因为它里面没有两种数字。
答案212
c
这题一定要注意判断日期合法性那个地方
#includeiostream
using namespace std;int main()
{int res0;for(int u0;u9;u)//出现 1 次的数 {for(int v0;v9;v)//出现 3 次的数 {if(uv)//这两个数不能相等 {continue;}int a0,b0,c0;//用来储存合法的年份、月份日期、时间 有几个相乘就是答案 for(int pos0;pos4;pos)//出现一次的数出现的位置在哪 {int nums[4];//将 uv 这两个数存入数组中 for(int i0;i4;i)//遍历数组 {if(ipos)//u是出现一次的数存一次 {nums[i]u;}else{nums[i]v;}}int ynums[0]*1000nums[1]*100nums[2]*10nums[3];//2020a;//年份都是合法的 int my/100,dy%100;if(m1m12d1d22)//判断日期合法性 //tips: 31 是无效的因为 若是存在31则只有一种情况是 1131,11月是没有31天的// 30 是无效的因为 不存在 0030 3330// 以此类推// 22 是有效的最大值 1222 0222 {b;}if(m0m23d0d59)//判断时间合法性 {c;}}resa*b*c;}}coutresendl;return 0;
}c语言暴力破解版
20分钟以上的运行时间
#includestdio.h
#includestring.hint tongji(char str[])
{int a[10]{0};int count0;for(int i0;i12;i){a[str[i]-0];}for(int i0;i10;i){if(a[i]!0)count;}return count;
}int tiaojian(char a[],char b[],char c[])
{int count10,count20,count30;int mcount10,mcount20,mcount30;int ma0,mb0,mc0;//确保三个数组中的三个元素是一样的否则会出现2022 0002 0002非法数据 for(int i0;i4;i){for(int j0;j4;j){if(a[i]a[j])count1;if(b[i]b[j])count2;if(c[i]c[j])count3;}if(mcount1count1){mcount1count1;maa[i];}if(mcount2count2){mcount2count2;mbb[i];}if(mcount3count3){mcount3count3;mcc[i];}count10,count20,count30;}if((mcount13mcount23mcount33)(mambmbmc))return 1;return 0;
}int get_string(int year,int day,int time)
{char years[5],days[5],times[5];char str[13];int i0;for(int k3;k0;k--)//倒着存则在数组里是正的数据 {years[k]year%100;year/10;days[k]day%100;day/10;times[k]time%100;time/10;}strcpy(str,years);strcat(str,days);strcat(str,times);
// puts(str);if(tongji(str)2)//判断数组里面的元素种类如 202220222022 的元素种类为 2 符合题意 {if(tiaojian(years,days,times)1)//判断数组里面的相同元素是否有3个如果相同元素有三个则说明满足题目条件2“ 3 个一种数字和 1 个另一种数字组成” {puts(str);return 1;}}return 0;
}int main(int argc, char *argv[])
{int months[13]{0,31,28,31,30,31,30,31,31,30,31,30,31};int i,j,l,k,m;int count0;for(i1;i9999;i){if((i%40i%100!0)||(i%4000))//判断日期合法性 months[2]29;for(j1;j12;j){for(l1;lmonths[j];l){for(k0;k24;k){for(m0;m60;m){if(get_string(i,j*100l,k*100m)1)count;}}}}}printf(%d,count);return 0;
}