高精度加法
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a,b;
a = sc.nextBigInteger();
b = sc.nextBigInteger();
System.out.println(a.add(b));
sc.close();
}
}
高精度减法
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a,b;
a = sc.nextBigInteger();
b = sc.nextBigInteger();
//System.out.println(a.add(b));
System.out.println(a.subtract(b));
sc.close();
}
}
高精度乘法
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a,b;
a = sc.nextBigInteger();
b = sc.nextBigInteger();
//System.out.println(a.add(b));
//System.out.println(a.subtract(b));
System.out.println(a.multiply(b));
sc.close();
}
}
高精度除法
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a,b;
a = sc.nextBigInteger();
b = sc.nextBigInteger();
//System.out.println(a.add(b));
//System.out.println(a.subtract(b));
//System.out.println(a.multiply(b));
System.out.println(a.divide(b));
System.out.println(a.mod(b));
sc.close();
}
}
队列
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
Deque<Integer> dq = new LinkedList<>();
for(int i=1;i<=n;i++)
dq.addLast(i);
//1 2 3 4 5 6 7 8 9 10
while(!dq.isEmpty()) {
for(int i=1;i<m;i++) {
dq.addLast(dq.getFirst());
dq.removeFirst();
}
System.out.print(dq.getFirst()+" ");
dq.removeFirst();
}
sc.close();
}
}
搞心态
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
sc.nextLine();
Deque<Integer> dq = new LinkedList<>();
while(q!=0) {
String[] s = sc.nextLine().split(" ");
if(s.length == 2) {
dq.addLast(Integer.parseInt(s[1]));
}else {
int n = Integer.parseInt(s[0]);
if(n == 2) {
dq.removeFirst();
}else {
System.out.println(dq.getFirst()+" "+dq.getLast());
}
}
q--;
}
sc.close();
}
}
队列模拟题目
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();//关键点
Deque<Integer> dq = new LinkedList<>();
while(n!=0) {
String[] s = sc.nextLine().split(" ");
if(s.length == 2) {
dq.addLast(Integer.parseInt(s[1]));
}else {
int m = Integer.parseInt(s[0]);
if(dq.isEmpty() && m == 2) {
System.out.println("lan");
}
if(dq.isEmpty() && m == 3) {
System.out.println("qiao");
}
if(!dq.isEmpty() && m == 2) {
dq.removeFirst();
}
if(!dq.isEmpty() && m == 3) {
System.out.println(dq.getFirst());
}
if(m == 4) {
System.out.println(dq.size());
}
}
n--;
}
sc.close();
}
}