#P0001. 使用说明!!!!!

使用说明!!!!!

一.各语言提交说明

Java

类名必须为Main,以下是P1000 A+B 一题的示例代码

import java.util.*;
// 注意类名必须为Main
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a + b);
    }
}

JavaScript

OJ暂时只支持Node.js模式。以下是P1000 A+B 一题的示例代码

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';

process.stdin.on('data', (data) => {
 input += data;
 return;
});
process.stdin.on('end', () => {
    // input数组以字符串形式存储了所有输入内容。input[i]存储第i行的所有内容.
    input = input.split('\n');
    // 在这里开始编写你的代码
    var arr = input[0].split(' ');
    var a = Number(arr[0]);
    var b = Number(arr[1]);
    console.log(a + b);
})

Python

暂无特殊说明

C++

暂无特殊说明

Go

二.快读快写优化说明

在输入量比较大的情况下容易出现输入输出所消耗的时间过多,导致被卡常超时。这种情况下需要使用快读快写。以下是各个语言的快读快写模板。

C++

快读

// 读入一个int整数
int read() {
    register int x = 0,f = 1;register char ch;
    ch = getchar();
    while(ch > '9' || ch < '0'){if(ch == '-') f = -f;ch = getchar();}
    while(ch <= '9' && ch >= '0'){x = x * 10 + ch - 48;ch = getchar();}
    return x * f;
}

快写

void write(int x){
	if(x<0){putchar('-');x=-x;}//若x为负数,输出符号并取其绝对值
	if(x>9){write(x/10);putchar(x%10+'0');}//输出绝对值(采用递归的做法,减少代码量)
	else putchar(x+'0');
	return; 
}

n1e8n \geq 1e8 时,比scanf,printf 快一倍左右

以下是P1000 A+B 一题的示例代码:

#include<bits/stdc++.h>
using namespace std;
int read() {
    register int x = 0,f = 1;register char ch;
    ch = getchar();
    while(ch > '9' || ch < '0'){if(ch == '-') f = -f;ch = getchar();}
    while(ch <= '9' && ch >= '0'){x = x * 10 + ch - 48;ch = getchar();}
    return x * f;
}
void write(int x){
	if(x<0){putchar('-');x=-x;}//若x为负数,输出符号并取其绝对值
	if(x>9){write(x/10);putchar(x%10+'0');}//输出绝对值(采用递归的做法,减少代码量)
	else putchar(x+'0');
	return; 
}
int main(){
    int a = read();
    int b = read();
    write(a + b);
    return 0;
}

Java

快读:FastReader 类

快写:PrintWriter 类,其定义后使用和System.out 用法一样,但是你不需要从System这个类中输出.

以下是P1000 A+B 一题的示例代码

import java.io.*;
import java.util.StringTokenizer;
// 注意类名必须为Main
class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int a = sc.nextInt();
        int b = sc.nextInt();
        out.println(a + b);
        // 最后记得flush,不然会没有输出
        out.flush();
    }
}
// 下面是快读模板。需要使用时直接贴在下面就好了
class FastReader{
    StringTokenizer st;
    BufferedReader br;
    public FastReader(){
        br=new BufferedReader(new InputStreamReader(System.in));
    }

    String next(){
        while (st==null||!st.hasMoreElements()){
            try {
                st=new StringTokenizer(br.readLine());
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

}

Python

速度大概快1/31/3 .同时你还可以选择pypy3编译器(如果平台提供)来获得更快的速度。

以下是P1000 A+B 一题的示例代码

import sys

input=lambda:sys.stdin.readline()
write=lambda x:sys.stdout.write(str(x)+'\n')

a , b  = list(map(int , input().split()))
write(a + b)

Go

使用ioutil.ReadAll

JavaScript

暂无