#include <iostream>
using namespace std;
unsigned short f(unsigned short x) {
x ^= x << 6;
x ^= x >> 8;
return x;
}
int main() {
unsigned short x;
cin >> x;
unsigned short y = f(x);
cout << y << endl;
return 0;
}假设输入的 $x$ 是不超过 $65535$ 的自然数,完成下面的判断题和单选题:
1. 当输入非零时,输出一定不为零。()
2. (2 分)将 f 函数的输入参数的类型改为 unsigned int,程序的输出不变。()
3. 当输入为 65535 时,输出为 63。()
4. 当输入为 1 时,输出为 64。()
5. 当输入为 512 时,输出为()。
6. 当输入为 64 时,执行完第 $5$ 行后 x 的值为()。
看到 unsigned short 移位 → 先想 16 位截断与补 0 规则
改类型成 int 会因位数变化导致溢出/补零规律全变,结果天差地别
考点:位运算规则|类型大小影响
函数 f 对 16 位无符号数做两次异或移位,整体是可逆变换,非零输入必得非零输出。