1.2编程基础之变量定义、赋值及转换
Portal:http://noi.openjudge.cn/ch0102/
一套水题,然而他们还是题
01-03是测基本数据类型存储空间大小
01
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { int a; short b; cout<<sizeof(a)<<' '<<sizeof(b); return 0; }
02
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { float a; double b; cout<<sizeof(a)<<' '<<sizeof(b); return 0; }
03
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { char a; bool b; cout<<sizeof(a)<<' '<<sizeof(b); return 0; }
额,其实sizeof()是一个在oi里比较冷门的语句,但是在测题目的空间能耗时,倒是有用
下次碰到sb题的时候就用它测一下所耗空间吧
对了
基本数据类型存储空间大小
bool 1(字节)
char 2
short 2
int 4
long 4
float 4
double 8
long double 16
long long 8
那么我们能从中明白什么呢?
我所明白的:
1.猥琐地用bool和char(+hash?)存储255以下的数据
2.对于256MiB的空间 数组最多开300W
对于65536KB的空间 数组最多开80W(各种基本数据结构)
3.不要vector里套个map,map里再套个pair和queue,不要做大常数大师
04 05:。。。你在逗我。。。各种意义上的答案题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { cout<<'D'<<' '<<'C'; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { cout<<'F'<<' '<<'E'; return 0; }
06 07 08 09:强制类型转换
格式有(类型说明符) (表达式) ,类型说明符((表达式))等等等等
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { float a; int b; cin>>a; b=a; cout<<b; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { char a; int b; cin>>a; b=a; cout<<b; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { int a; char b; cin>>a; b=a; cout<<b; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { int a; bool b; cin>>a; b=a; a=b; cout<<a; return 0; }
10:呵呵 ”Hello, World!的大小“ 这题也是可以
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdio> int main() { printf("%d",sizeof("Hello, World!")); return 0; }
综合来说:题虽然水,但挺好的,这些题注重的不是练习和结果,而是引导学生去“探究”C++的语言用法和标准
不得不说,ccf还是干了好事的