关于杭电OnlineJudge一些注意事项

来源:互联网 发布:做知敬畏守底线的党员 编辑:程序博客网 时间:2024/06/05 18:25

 1.     关于头文件的引用

若使用头文件iostream.h而不是iostream再引用标准名空间,有部分输入输出流的函数无法使用

2.     关于输入/输出速度和范围

输入输出流(iostream)易于使用,可是运行速度比标准输入输出(stdio)慢,可能引起超时,如果输入或输出的数据超过1M,应该使用标准输入输出(scanf, printf…)

读字符的函数在读入编码为128~255的字符时,返回负值,如果输入数据中包含这样的符号,需声明为无符号字符型(unsigned char)

3.     C++关键字

声明变量时不能使用关键字,下面列出了C++的关键字(除以“__”开头的关键字之外)

bool             naked                thread

catch            namespace            throw

const_cast       noinline             true

deprecated       noreturn             try

dllexport        nothrow              typeid

dllimport        novtable             typename

dynamic_cast     property             using

explicit         reinterpret_cast     uuid

false            selectany            wchar_t

mutable          static_cast

4.     编译器

①    服务器上没有头文件“conio.h”,因为这个文件包含的函数在解决问题时不需要

②    使用头文件“math.h”里的函数,不能用整型变量作为参数,例如:sqrt(2)应写成sqrt((double)2) or sqrt(2.0)

③    头文件“math.h”包含了函数j0, j1, jn, y0, y1, and yn,因此如果使用了该头文件,在声明全局变量时不能使用这些变量名

④    long double和double一样,sizeof(long double) = sizeof(double) = 8,解题时,除非题目特别要求使用float类型,否则使用double类型就足够了

    When solving problems, it is always sufficient to use the type double (unless a special implementation of floating-point numbers is required). (理解可能存在偏差)

⑥    在GCC/G++中不存在函数itoa,可以使用函数sprintf替代

⑦    不支持常数M_PI,必须自行定义,例如:const double PI = acos(-1.0)

⑧    在for循环中声明的变量,作用范围仅在该for循环内部

5.     尾随在每行末的空白字符和尾随在输出结果之后的空行不被视为格式错误

6.     如何使用64位整形

有符号位的64位整形表示的数据范围是

–9223372036854775808 到 9223372036854775807

无符号的64位整形表示的数据范围是 0 到 18446744073709551615

有如下两种声明方法:

__int64 a;

unsigned __int64 b;

long long a;

unsigned long long b;

读写根据不同的输入输出函数库而不同:

#include <stdio.h>

...

scanf("%I64d", &a);

scanf("%I64u", &b);

printf("%I64d", a);

printf("%I64u", b);

 

#include <iostream>

using namespace std;

...

cin >> a;

cin >> b;

cout << a;

cout << b;

注:如果使用头文件iostream.h,64位整型是无法使用的

7.     读入数据

Language

C

C++

To read numbers

int n;
while(scanf("%d", &n) != EOF){
  ...}

int n;
while (cin >> n){
  ...}

To read characters

int c;
while ((c = getchar()) != EOF){
  ...}

char c;
while (cin.get(c)){
  ...}

To read lines

char line[1024];
while(gets(line)){
  ...}

string line;
while (getline(cin, line)){
  ...}

 

原创粉丝点击