输出 OpenJudge C/C++ 环境中 int 与 short 的固定字节数。
OJ: noi_openjudge
题目 ID: ch0102-01
难度:入门
标签:输入输出python
日期: 2026-07-30 23:01
题意
输出题目指定的 C/C++ 评测环境中 int 与 short 的存储空间大小。
思路
这不是查询 Python 对象大小的题。sys.getsizeof 会包含 Python 对象的运行时开销,和 C/C++ 的 sizeof 没有可比性。根据题目所在平台,int 为 4 字节、short 为 2 字节,直接输出这两个固定值。
代码
Python代码
python
# OpenJudge 的 C/C++ 环境中,int 和 short 分别占 4、2 个字节。
print(4, 2)C++代码
这里保留原有的 C++ 参考实现。
cpp
/*
* int 4
* double 8
* float 4
* bool 1
* char 1
*
* sizeof
* */
#include <cstdio>
// sizeof 不是函数
// #define sizeof(int) 4
int main(){
int a = sizeof(int);
int b = sizeof(short);
printf("%d %d",a,b);
return 0;
}复杂度
时间复杂度和额外空间复杂度均为
总结
语言数据类型的大小由实现决定;在这道 OJ 题中,目标平台已经固定,Python 解法应输出该平台的结论。