-
Proceed to the end of file.
在Input要求中看到这句话,就代表样例数据要一直输入到没有输入了为止,常见方法是(假设每组数据要输入n与m):while(cin>>n>>m){ }
while(scanf("%d %d",&n,&m) == 2){ }
while (~scanf("%d %d",&n,&m)){ } while (scanf("%d%d",&m,&n) != EOF) { }
这两行的意思是一样的,scanf的返回值是成功输入变量的个数,假如输入出错就返回EOF(定义为-1),~按位取反后就为0,退出循环。如果此循环结束后还需要输入数据,那么因为它会把错误数据也读入stdin导致影响到下一步。
按Ctrl+Z再按Enter可结束。 -
PI定义:需要<cmath>
const double PI = acos(-1.0);
学会多用const
-
float,double输入输出
输入:double用%lf,float用%f
输出:C99都用%f,C89的double可以%lf -
gets()在C11中被移除了
keep it simple and stupid -
C++各种类型数范围
#include <iostream> #include <limits> using namespace std; int main() { cout<<"int bytes: "<<sizeof(int)<<endl<< "min: "<<(numeric_limits<int>::min)()<< " max: "<<(numeric_limits<int>::max)()<<endl<<endl; cout<<"double bytes: "<<sizeof(double)<<endl<< "min: "<<(numeric_limits<double>::min)()<< " max: "<<(numeric_limits<double>::max)()<<endl<<endl; cout<<"long long bytes: "<<sizeof(long long)<<endl<< "min: "<<(numeric_limits<long long>::min)()<< " max: "<<(numeric_limits<long long>::max)()<<endl<<endl; cout<<"long double bytes: "<<sizeof(long double)<<endl<< "min: "<<(numeric_limits<long double>::min)()<< " max: "<<(numeric_limits<long double>::max)()<<endl<<endl; cout<<"bool size: "<<sizeof(bool)<<endl; cout<<"char size: "<<sizeof(char)<<endl; return 0; }
据类型 字节 min max int 4 -2147483648 2147483647 double 8 2.22507e-308 1.79769e+308 long long 8 -9223372036854775808 9223372036854775807 long double 12 3.3621e-4932 1.18973e+4932 char 1 bool 1 -
不要使用/<conio.h/>,不要使用getch()
近日算法零碎知识笔记(一)
最新推荐文章于 2023-09-06 23:42:45 发布