实体类

import lombok.Getter;
import lombok.Setter; @Getter
@Setter
public class Student { private int id;
private String name;
private String score;
private int classNo; public Student(int id, String name, String score, int classNo) {
this.id = id;
this.name = name;
this.score = score;
this.classNo = classNo;
}
}

Main

import com.demo.entity.Student;

import java.util.*;
import java.util.stream.Collectors; public class Main { private static List<String> simpleList = new ArrayList<>();
private static List<Student> normalList = new ArrayList<>();
static {
simpleList.add("apple");
simpleList.add("apple");
simpleList.add("banana");
simpleList.add("orange"); normalList.add(new Student(1, "Emma", "A", 701));
normalList.add(new Student(2, "Larissa", "S", 701));
normalList.add(new Student(3, "Sophia", "B", 701));
normalList.add(new Student(4, "Ashley", "B", 702));
normalList.add(new Student(5, "May", "C", 702));
normalList.add(new Student(6, "Hailey", "D", 702));
normalList.add(new Student(7, "Kelly", "S", 703));
normalList.add(new Student(8, "Amy", "A", 703));
normalList.add(new Student(9, "Wesley", "C", 703));
}
public static void main(String[] args){
// TODO
} }

List<String> 转 Set<String>

System.out.println("----------------简单List---------------");
simpleList.forEach(System.out::println);
System.out.println("----------------简单List转Set---------------");
Set<String> simpleSet = new HashSet<>(simpleList);
simpleSet.forEach(System.out::println);

输出:

----------------简单List---------------
apple
apple
banana
orange
----------------简单List转Set---------------
banana
orange
apple

List<Student> 转 Set<Integer>

System.out.println("----------------普通List---------------");
normalList.forEach(System.out::println);
System.out.println("----------------普通List转Set---------------");
Set<Integer> normalSet = normalList.stream().map(Student::getClassNo).collect(Collectors.toSet());
normalSet.forEach(System.out::println);

输出:

----------------普通List---------------
Student{id=, name='Emma', score='A', classNo=}
Student{id=, name='Larissa', score='S', classNo=}
Student{id=, name='Sophia', score='B', classNo=}
Student{id=, name='Ashley', score='B', classNo=}
Student{id=, name='May', score='C', classNo=}
Student{id=, name='Hailey', score='D', classNo=}
Student{id=, name='Kelly', score='S', classNo=}
Student{id=, name='Amy', score='A', classNo=}
Student{id=, name='Wesley', score='C', classNo=}
----------------普通List转Set---------------

List<Student> 转 List<String>

System.out.println("----------------普通List转List---------------");
List<String> list = normalList.stream().map(Student::getName).collect(Collectors.toList());
list.forEach(System.out::println);

输出:

----------------普通List转List---------------
Emma
Larissa
Sophia
Ashley
May
Hailey
Kelly
Amy
Wesley

List<Student> 转 Map<Integer,Student>

System.out.println("----------------普通List转Map---------------");
Map<Integer,Student> normalMap = normalList.stream().collect(Collectors.toMap(Student::getId,(b)->b));
normalMap.forEach((id, student) -> {
System.out.println(id + "::" + student);
});

输出:

----------------普通List转Map---------------
::Student{id=, name='Emma', score='A', classNo=}
::Student{id=, name='Larissa', score='S', classNo=}
::Student{id=, name='Sophia', score='B', classNo=}
::Student{id=, name='Ashley', score='B', classNo=}
::Student{id=, name='May', score='C', classNo=}
::Student{id=, name='Hailey', score='D', classNo=}
::Student{id=, name='Kelly', score='S', classNo=}
::Student{id=, name='Amy', score='A', classNo=}
::Student{id=, name='Wesley', score='C', classNo=}

复杂一点的转换:(List转Map处理重复key)

List<Student> students = new ArrayList<>(normalList);
System.out.println("----------------原数据---------------");
students.forEach(System.out::println);
System.out.println("----------------List<Student>转Map<String, Student>重复key只保留前者---------------");
// 重复key处理 (s1, s2) -> s1)
Map<Integer, Student> classStudentMap = students.stream().collect(Collectors.toMap(Student::getClassNo, s -> s, (s1, s2) -> s1));
classStudentMap.forEach((classNo, student) -> System.out.println(classNo + "::" + student)); System.out.println("----------------List<Student>转Map<String, List<Student>>---------------");
// 重复key处理成一个集合
Map<Integer, List<Student>> listMap = students.stream().collect(Collectors.toMap(Student::getClassNo, s -> {
List<Student> l = new ArrayList<>();
l.add(s);
return l;
}, (List<Student> s1, List<Student> s2) -> {
s1.addAll(s2);
return s1;
}));
listMap.forEach((learn, student) -> System.out.println(learn + "::" + student));

输出:

----------------原数据---------------
Student{id=, name='Emma', score='A', classNo=}
Student{id=, name='Larissa', score='S', classNo=}
Student{id=, name='Sophia', score='B', classNo=}
Student{id=, name='Ashley', score='B', classNo=}
Student{id=, name='May', score='C', classNo=}
Student{id=, name='Hailey', score='D', classNo=}
Student{id=, name='Kelly', score='S', classNo=}
Student{id=, name='Amy', score='A', classNo=}
Student{id=, name='Wesley', score='C', classNo=}
----------------List<Student>转Map<String, Student>重复key只保留前者---------------
::Student{id=, name='Emma', score='A', classNo=}
::Student{id=, name='Ashley', score='B', classNo=}
::Student{id=, name='Kelly', score='S', classNo=}
----------------List<Student>转Map<String, List<Student>>---------------
::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Sophia', score='B', classNo=}]
::[Student{id=, name='Ashley', score='B', classNo=}, Student{id=, name='May', score='C', classNo=}, Student{id=, name='Hailey', score='D', classNo=}]
::[Student{id=, name='Kelly', score='S', classNo=}, Student{id=, name='Amy', score='A', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]

Map<String, List<Student>>转List<Student> 和 Map<String, List<Student>>转List<List<Student>>

List<Student> students = new ArrayList<>(normalList);
// 先分组,准备好数据
Map<String, List<Student>> grouping = students.stream().collect(Collectors.groupingBy(Student::getScore));
System.out.println("----------------Map<String, List<Student>>转List<Student>---------------");
// 把map的values全部拆出来
List<Student> collect = grouping.entrySet().stream()
.flatMap(map -> map.getValue().stream())
.collect(Collectors.toList());
collect.forEach(System.out::println); System.out.println("----------------Map<String, List<Student>>转List<List<Student>>---------------");
// 只要map的value,但是不改变格式
grouping.values().forEach(System.out::println);

输出:

----------------Map<String, List<Student>>转List<Student>---------------
Student{id=, name='Emma', score='A', classNo=}
Student{id=, name='Amy', score='A', classNo=}
Student{id=, name='Sophia', score='B', classNo=}
Student{id=, name='Ashley', score='B', classNo=}
Student{id=, name='May', score='C', classNo=}
Student{id=, name='Wesley', score='C', classNo=}
Student{id=, name='Larissa', score='S', classNo=}
Student{id=, name='Kelly', score='S', classNo=}
Student{id=, name='Hailey', score='D', classNo=}
----------------Map<String, List<Student>>转List<List<Student>>---------------
[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
[Student{id=, name='Hailey', score='D', classNo=}]

分组

List<Student> students = new ArrayList<>(normalList);
System.out.println("----------------分组---------------");
// 根据key分组
Map<String, List<Student>> grouping = students.stream().collect(Collectors.groupingBy(Student::getScore));
grouping.forEach((score, student) -> System.out.println(score + "::" + student));
System.out.println("----------------按照多个属性分组---------------");
// 根据多个key的组合分组
grouping = students.stream().collect(Collectors.groupingBy( e -> e.getClassNo() + "_" + e.getScore()));
grouping.forEach((learn, student) -> System.out.println(learn + "::" + student));

输出:

----------------分组---------------
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
----------------按照多个属性分组---------------
702_C::[Student{id=, name='May', score='C', classNo=}]
703_A::[Student{id=, name='Amy', score='A', classNo=}]
702_B::[Student{id=, name='Ashley', score='B', classNo=}]
701_S::[Student{id=, name='Larissa', score='S', classNo=}]
703_C::[Student{id=, name='Wesley', score='C', classNo=}]
703_S::[Student{id=, name='Kelly', score='S', classNo=}]
702_D::[Student{id=, name='Hailey', score='D', classNo=}]
701_B::[Student{id=, name='Sophia', score='B', classNo=}]
701_A::[Student{id=, name='Emma', score='A', classNo=}]

排序

List<Student>根据名字排序

System.out.println("----------------List排序---------------");
// 虽然这里是浅拷贝,但是只影响修改而不影响排序
List<Student> students = new ArrayList<>(normalList);
Collections.sort(students, Comparator.comparing(Student::getName));
// 比上面更简洁
// students.sort(Comparator.comparing(Student::getName));
students.forEach(System.out::println);

输出:

----------------List排序---------------
Student{id=8, name='Amy', score='A', classNo=703}
Student{id=4, name='Ashley', score='B', classNo=702}
Student{id=1, name='Emma', score='A', classNo=701}
Student{id=6, name='Hailey', score='D', classNo=702}
Student{id=7, name='Kelly', score='S', classNo=703}
Student{id=2, name='Larissa', score='S', classNo=701}
Student{id=5, name='May', score='C', classNo=702}
Student{id=3, name='Sophia', score='B', classNo=701}
Student{id=9, name='Wesley', score='C', classNo=703}

List<String>排序

System.out.println("----------------简单List排序---------------");
List<String> list = new ArrayList<>(simpleList);
System.out.println("----------------正序---------------");
list.sort((a,b) -> a.compareTo(b));
// 更简洁的方式
// list.sort(Comparator.naturalOrder());
list.forEach(System.out::println);
System.out.println("----------------倒序---------------");
list.sort(Comparator.reverseOrder());
list.forEach(System.out::println);

输出:

----------------简单List排序---------------
----------------正序---------------
apple
apple
banana
orange
----------------倒序---------------
orange
banana
apple
apple

Map排序

List<Student> students = new ArrayList<>(normalList);
// 先按照成绩分组,准备好数据
Map<String, List<Student>> grouping = students.stream().collect(Collectors.groupingBy(Student::getScore));
System.out.println("----------------Map<String, List<Student>>排序---------------");
Map<String, List<Student>> result = new LinkedHashMap<>();
// Map的key有特殊处理
grouping.entrySet().stream()
.sorted((o1,o2) -> {
Integer k1 = getWeight(o1.getKey());
Integer k2 = getWeight(o2.getKey());
return k1.compareTo(k2);
})
.forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
result.forEach((learn, student) -> System.out.println(learn + "::" + student));
System.out.println("----------------");
Map<String, List<Student>> result2 = new LinkedHashMap<>();
// 仅仅按照key排序
grouping.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEachOrdered(x -> result2.put(x.getKey(), x.getValue()));
result2.forEach((learn, student) -> System.out.println(learn + "::" + student));
System.out.println("----------------");
Map<String, List<Student>> result3 = new LinkedHashMap<>();
// 等价第一个,只是省去了getKey方法
grouping.entrySet().stream()
.sorted(Map.Entry.comparingByKey((o1,o2) -> {
Integer k1 = getWeight(o1);
Integer k2 = getWeight(o2);
return k1.compareTo(k2);
}))
.forEachOrdered(x -> result3.put(x.getKey(), x.getValue()));
result3.forEach((learn, student) -> System.out.println(learn + "::" + student));

权重方法:

/**
* 不同成绩有不同的排序权重
* @param score
* @return
*/
public static Integer getWeight(String score){
switch (score){
case "S": return 1;
case "A": return 2;
case "B": return 3;
case "C": return 2;
case "D": return 2;
default:return 0;
}
}

输出:

----------------Map<String, List<Student>>排序---------------
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
----------------
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
----------------
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]

如果你要倒序的话

System.out.println("----------------倒序----------------");
Map<String, List<Student>> result4 = new LinkedHashMap<>();
// 仅仅按照key排序
grouping.entrySet().stream()
.sorted(Map.Entry.<String, List<Student>>comparingByKey().reversed())
.forEachOrdered(x -> result4.put(x.getKey(), x.getValue()));
result4.forEach((learn, student) -> System.out.println(learn + "::" + student));
System.out.println("----------------");
Map<String, List<Student>> result5 = new LinkedHashMap<>();
// 等价第一个,只是省去了getKey方法
grouping.entrySet().stream()
.sorted(Map.Entry.<String, List<Student>>comparingByKey((o1,o2) -> {
Integer k1 = getWeight(o1);
Integer k2 = getWeight(o2);
return k1.compareTo(k2);
}).reversed())
.forEachOrdered(x -> result5.put(x.getKey(), x.getValue()));
result5.forEach((learn, student) -> System.out.println(learn + "::" + student));

输出:

----------------倒序----------------
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
----------------
B::[Student{id=, name='Sophia', score='B', classNo=}, Student{id=, name='Ashley', score='B', classNo=}]
A::[Student{id=, name='Emma', score='A', classNo=}, Student{id=, name='Amy', score='A', classNo=}]
C::[Student{id=, name='May', score='C', classNo=}, Student{id=, name='Wesley', score='C', classNo=}]
D::[Student{id=, name='Hailey', score='D', classNo=}]
S::[Student{id=, name='Larissa', score='S', classNo=}, Student{id=, name='Kelly', score='S', classNo=}]

统计

String s = "15, 11, 01, 03, 07, 12, 15, 12, 15, 02, 07, 14, 01, 03, 04, 05, 09, 04, 06, 12, 04, 07, 13, 10, 04, 14, 13, 11, 10, 16, 16, 04, 15, 03, 16, 08, 10, 05, 08, 11, 16, 04, 13, 07, 14, 06, 14, 10, 15, 02, 09, 16, 08, 11, 10, 01, 16, 12, 06, 01, 12, 01, 16, 12, 10, 04";
List<Integer> list = new ArrayList<>();
for(String i : s.split(", ")){
list.add(Integer.valueOf(i));
}
// 平均值
System.out.println(list.stream().mapToDouble(value -> value).average());
// 总值
System.out.println(list.stream().mapToDouble(value -> value).sum());
// 数据数量
System.out.println(list.stream().mapToDouble(value -> value).count());
// 最大
System.out.println(list.stream().mapToDouble(value -> value).max());
// 最小
System.out.println(list.stream().mapToDouble(value -> value).min());
// 去重后计算总值
System.out.println(list.stream().mapToDouble(value -> value).distinct().sum());

也有其他数据类型的方法

结果:

OptionalDouble[9.121212121212121]
602.0
66
OptionalDouble[16.0]
OptionalDouble[1.0]
136.0

=========================================分割线=================================================

Lambda表达式

格式:(params) -> {expression}

比如我们实现一个Runnable接口

Runnable run = new Runnable() {
@Override
public void run() {
// TODO
}
};

使用Lambda表达式

Runnable run = () -> {
// TODO
};

而可以使用Lambda的接口也是有限制的,即只能有一个方法。

函数式接口

规范:

1. 接口中只能有一个抽象方法

2. (可选)在接口上添加 @FunctionalInterface 注解,这样可以检测它是否是一个函数式接口。

比如:

@FunctionalInterface
public interface Fun{
void fun();
} // 也可以使用泛型
@FunctionalInterface
public interface Fun<T>{
void fun(T t);
}

使用的时候

Fun fun = () -> {};

为什么Lambda引用外部变量需要final修饰?

1. 每个方法执行的时候都会在栈上创建一个栈帧,局部变量存放在栈帧中的局部变量表中,栈上的内容是线程私有的。

2. Lambda表达式是个匿名函数,准确来说是个匿名内部类接口的实现方法。而执行此代码的线程会在执行的时候单独创建一个栈帧,局部变量依然是私有的。

3. 由此可见,表达式里的current变量只是外部current变量的一个副本。而为了保证程序的正确性则强制要求这个被引用的局部变量被定义成final。

也就是说,人家也可以不加入这个检查,允许你改变外部局部变量的值,但是,程序运行的结果并不会如你所愿,所以,人家索性就打消你这个念头。

其它Java8新特性

1. computeIfAbsent

Map<String, String> map = new HashMap<>();
String key = "A";
String v = map.get(key);
if (v == null){
System.out.println("处理key不存在的情况");
}

Java8可以这样处理

Map<String, String> map = new HashMap<>();
String key = "A";
String computeIfAbsent = map.computeIfAbsent(key, s -> {
return "如果key不存在,则返回这个";
});
System.out.println(computeIfAbsent);

2. filter

过滤出特定数据,并取出特定字段

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors; public class Main {
public static void main(String[] args) throws Exception {
List<People> list = new ArrayList<>();
list.add(new People(1, "男"));
list.add(new People(2, "女"));
list.add(new People(3, "女")); List<Integer> collect = list.stream().filter(i -> "女".equals(i.getSex())).map(People::getId).collect(Collectors.toList());
System.out.println(collect);
} } @Getter
class People{
private int id;
private String sex; public People(int id, String sex) {
this.id = id;
this.sex = sex;
}
}

输出

随时补充

java8 List<对象> 转 Set、Map(高级)的更多相关文章

  1. java8新特性:对map集合排序

    一.简单介绍Map 在讲解Map排序之前,我们先来稍微了解下map,map是键值对的集合接口,它的实现类主要包括:HashMap, TreeMap, Hashtable以及LinkedHashMap等 ...

  2. Map.putAll方法——追加另一个Map对象到当前Map集合(转)

    该方法用来追加另一个Map对象到当前Map集合对象,它会把另一个Map集合对象中的所有内容添加到当前Map集合对象. 语法  putAll(Map<? extends K,? extends V ...

  3. 将Object对象转换成Map 属性名和值的形式

    将Java对象转换成Map的键值对形式 代码: package cn.lonelcoud.util; import com.sun.deploy.util.StringUtils; import ja ...

  4. Java对象转换成Map

    需求总是千奇百怪,对象转成map,看似没必要,但就是有这个需求,所以记录下来 首先是Bean package tools; import lombok.Data; /** * 车辆实体类 */ @Da ...

  5. Java8从对象列表中取出某个属性的列表

    List<属性值类型> 属性List = 对象List.stream().map(对象::get方法()).collect(Collectors.toList()); 例如: List&l ...

  6. Map.putAll方法——追加另一个Map对象到当前Map集合

    转: Map.putAll方法——追加另一个Map对象到当前Map集合(转) 该方法用来追加另一个Map对象到当前Map集合对象,它会把另一个Map集合对象中的所有内容添加到当前Map集合对象. 语法 ...

  7. 对象Bean与Map互转问题

    一.摘要 在实际开发过程中,经常碰到需要进行对象与map之间互转的问题,其实对于对象.Map 之间进行互转有很多种方式,下面我们一起来梳理一下: 利用 JSON 工具包,将对象转成字符串,之后再转成 ...

  8. java8 快速实现List转map 、分组、过滤等操作

    利用java8新特性,可以用简洁高效的代码来实现一些数据处理. 定义1个Apple对象: public class Apple { private Integer id; private String ...

  9. java8中optional和.stream().map()

    使用optional的好处:是一个可以包含或不可以包含非空值的容器对象,更加友好的处理程序中的空对象. Optional<T>有方法 isPresent() 和 get() 是用来检查其包 ...

随机推荐

  1. vue-cli:渲染过程理解2(vue init webpack方式创建)

    main.js: 入口文件 import Vue from 'vue' //引入node_modules中的vue import App from './App' //引入当前路径(src)下的App ...

  2. C-Lodop设置页面一加载就打印

    C-Lodop由于是服务不是np插件,调用打印语句(print或preview等)时机太早,在页面第一次加载完成后有几百毫秒时间等待WebSocket通讯服务准备完成,在没完成的时候会提示“C-Lod ...

  3. Clover file list

    /Volumes/EFI//EFI: total 4 drwxrwxrwx 1 jianweiliu staff 512 Apr 20 12:17 APPLE drwxrwxrwx@ 1 jianwe ...

  4. BZOJ 1800 [Ahoi2009]fly 飞行棋

    题目链接 思路 终于有一道自己想出来的题了,开心. 因为是矩形,一定有直角,所以考虑直径,之后由于矩形对角线是两条直径,所以考虑组合数. 直径有n条,矩形有c(n,2)个. #include<i ...

  5. CentOS安装GIt、上传项目到git仓库

    上传项目 登录服务器后安装git yum install git 新建文件夹(仓库) mkdir *.git 初始化仓库 git init --bare *.git 在本地初始化仓库 git init ...

  6. [BZOJ 2743] [HEOI 2012] 采花

    Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了 \(n\) 朵花,花有 \(c\) 种颜色(用整数 \ ...

  7. 初步了解HTML

    超文本标记语言(英语:HyperText Markup Language,简称:HTML)是一种用于创建网页的标准标记语言. 您可以使用 HTML 来建立自己的 WEB 站点,HTML 运行在浏览器上 ...

  8. 图论杂项细节梳理&模板(虚树,圆方树,仙人掌,欧拉路径,还有。。。)

    orzYCB 虚树 %自为风月马前卒巨佬% 用于优化一类树形DP问题. 当状态转移只和树中的某些关键点有关的时候,我们把这些点和它们两两之间的LCA弄出来,以点的祖孙关系连成一棵新的树,这就是虚树. ...

  9. 环境变量PS1,修改命令行提示符样式

    推荐模板  export PS1="\[\e[37;40m\][\[\e[31;40m\]\u\[\e[0m@\[\e[33;40m\]\H \[\e[36;40m\]\w\[\e[0m\] ...

  10. 【BZOJ3601】一个人的数论(数论)

    [BZOJ3601]一个人的数论(数论) 题面 BZOJ 怎么这图片这么大啊... 题解 要求的是\(\displaystyle \sum_{i=1}^n [gcd(i,n)=1]i^d\) 然后把\ ...