真题见如下链接
第一题
如果实在不会了直接char强制转换int也可以做啊,忽略了。
第二题
科普一下:1Mb = 1024Kb = 1024 * 1024b
可以通过sizeof(int)得到 int的字节数为4
所以这道题的答案为256*1024*1024/4=67108864
第三题
一道简单的模拟题,直接看代码。
//Problem C
#include <iostream>
using namespace std;
int n[10];//用于存储每一个数字卡片剩余张数
bool check(int a)
{
while (a > 0)
{
int tmp = a % 10;
a /= 10;
n[tmp]--;//剩余张数减一
if (n[tmp] == -1)//这个数字无法组合
{
return true;
}
}
return false;
}
int main()
{
for (int i = 0; i < 10; i++)
{
n[i] = 2021;//初始化,每个数字都有2021张
}
int i = 1;
for (i;; i++)
{
bool f = check(i);
if (f)
break;
}
cout << i - 1 << endl;
return 0;
}
第四题
略,等学完图论补充。
第五题
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
int main()
{
LL t;
scanf("%lld", &t);
t /= 1000;//毫秒转秒
t %= 86400;//精确到一天的秒数
int hh = t / 3600;
t %= 3600;
int mm = t / 60;
t %= 60;
int ss = t;
printf("%0.2d:%0.2d:%0.2d\n", hh, mm, ss);
return 0;
}
第六题
很妙啊,参考https://zhuanlan.zhihu.com/p/37895166
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int index = 1, count = 1, weight = 1;
while (weight < n) {
count++;
index *= 3;
weight += index;
}
cout << count << endl;
return 0;
}
后面的太晚了,明天继续肝