【Java】Java划水练习
2024-10-21 18:48:50
bzoj1000 A+B Problem
Scanner sc=new Scanner(new BufferedInputStream(System.in)); 声明读入器
nextInt 读入整数
System.out.println 带换行输出
import java.util.*;
import java.io.*; public class Main{
public static void main(String[] argc){
Scanner sc = new Scanner (new BufferedInputStream(System.in));
int a=sc.nextInt(),b=sc.nextInt();
System.out.println(a+b);
sc.close();
}
}
poj1503 Integer Inquiry
BigInteger.ZERO 大整数常量零
equals 相等
add 加
import java.util.*;
import java.io.*;
import java.math.*; public class Main{
public static void main(String[] argc){
Scanner sc = new Scanner (new BufferedInputStream(System.in));
BigInteger sum=BigInteger.ZERO;
while(true){
BigInteger x=sc.nextBigInteger();
if(x.equals(BigInteger.ZERO)){
break;
}
sum=sum.add(x);
}
System.out.println(sum);
sc.close();
}
}
poj1001 求高精度幂
stripTrailingZeros 清除不影响大小的零
toPlainString 以朴素的方式(而非科学计数法或工程计数法)将BigDecimal转换成String
hasNext 判断是否读入完成
next 读入字符串,直到空格为止
nextLine 读入一整行字符串
public String substring(int beginIndex) 返回该字符串从beginIndex开始到结尾的子字符串;
public String substring(int beginIndex,int endIndex) 返回该字符串从beginIndex开始到endsIndex结尾的子字符串
import java.util.*;
import java.io.*;
import java.math.*; public class Main {
public static void main(String[] argc){
Scanner sc=new Scanner(new BufferedInputStream(System.in));
while(sc.hasNext()){
String s=sc.next();
int n=sc.nextInt();
BigDecimal x=new BigDecimal(s);
s=x.pow(n).stripTrailingZeros().toPlainString();
if(s.charAt(0)=='0'){
s=s.substring(1);
}
System.out.println(s);
}
sc.close();
}
}
bzoj1876 [SDOI2009]SuperGCD
gcd 求两个大整数的gcd
import java.util.*;
import java.io.*;
import java.math.*; public class Main {
public static void main(String[] argc){
Scanner sc=new Scanner(new BufferedInputStream(System.in));
BigInteger a=sc.nextBigInteger();
BigInteger b=sc.nextBigInteger();
System.out.println(a.gcd(b));
sc.close();
}
}
最新文章
- C# socket UDPの异步链接
- maven2-snapshot快照库和release发布库的应用
- HOJ 2678 Stars
- 专题实验 PGA
- DISP_FUNCTION用法
- MYSQL日常操作命令再熟悉
- GUI编程笔记(java)07:GUI把文本框的值移到文本域案例
- Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五)
- 批处理Bat实现整合定时关机或取消定时关机
- BCDBOOT命令参数介绍
- Hadoop 新生报道(二) hadoop2.6.0 集群系统版本安装和启动配置
- amazeui表单form异步提交方法
- 我知道的nginx配置
- Windows 下配置 Apache 支持 https
- Spring Cloud 各组件调优参数
- Gitkraken的使用
- 几个简单易懂的排序算法php
- 【C/C++】C/C++中Static的作用详述
- maven学习(3)-Maven 核心技术
- 开始第一个Android应用程序