Java算法竞赛使用手册

一、输入

【输入格式】

第一行包含一个整数N。
第二行包含N个整数A1, A2, … AN。
第三行包含N个整数B1, B2, … BN。
第四行包含N个整数C1, C2, … CN。

【样例输入】

3
1 1 1
2 2 2
3 3 3

import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n,count=0;
		int[][] a = new int[3][100001];
		
		Scanner in = new Scanner(new BufferedInputStream(System.in)); 
        n = in.nextInt(); 
        for(int i=0;i<3;i++)
		for(int j=0;j<n;j++)
				 a[i][j]=in.nextInt();
	}
}
输入挂

Scanner in = new Scanner(new BufferedInputStream(System.in));

读一个整数:int n = sc.nextInt();

读一个字符串:String s = sc.next();

读一个浮点数:double t = sc.nextDouble();

读一整行: String s = sc.nextLine();

判断是否有下一个输入sc.hasNext()sc.hasNextInt()sc.hasNextDouble()sc.hasNextLine()

二、文件读写

文件读取

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class 文件读取 {
	public static void main(String[] args) {
        String pathname = "input.txt"; 
        try (FileReader reader = new FileReader(pathname);
             BufferedReader br = new BufferedReader(reader) 
        ) {
            String line;
            while ((line = br.readLine()) != null) { 
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
}

文件写入

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class 文件写入 {
	public static void main(String[] args) {
		try {
            File writeName = new File("output.txt"); 
            writeName.createNewFile(); 
            try (FileWriter writer = new FileWriter(writeName);
                 BufferedWriter out = new BufferedWriter(writer)
            ) {
                out.write("123\r\n"); 
                out.write("1 2 3"); 
                out.flush(); 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

大数类

import java.math.BigInteger;
public class 大数类 {
	public static void main(String[] args) {
		BigInteger bi1 = new BigInteger("12") ;	// 声明BigInteger对象
		BigInteger bi2 = new BigInteger("15") ;	// 声明BigInteger对象
		System.out.println("加法操作:" + bi2.add(bi1)) ;	// 加法操作
		System.out.println("减法操作:" + bi2.subtract(bi1)) ;	// 减法操作
		System.out.println("乘法操作:" + bi2.multiply(bi1)) ;	// 乘法操作
		System.out.println("除法操作:" + bi2.divide(bi1)) ;	// 除法操作
		System.out.println("最大数:" + bi2.max(bi1)) ;	 // 求出最大数
		System.out.println("最小数:" + bi2.min(bi1)) ;	 // 求出最小数
		BigInteger result[] = bi2.divideAndRemainder(bi1) ;	// 求出余数的除法操作
		System.out.println("商是:" + result[0] + 
			";余数是:" + result[1]) ;
	}
}
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值