├── .gitignore ├── BATHM Exam └── huawei1.c ├── PAT with C ├── PublicBikeADV1018.java ├── patA1005.c ├── patA1028.c ├── patA1032c ├── patA1042.c ├── patA1049.c ├── patA1074.c ├── patA1093.c ├── patB1001.c ├── patB1015.c ├── patB1016.c ├── patB1025.c └── patB1026.c ├── README.md └── notes ├── Centos-Linux-quick.md ├── SSH-SCP.md ├── git-shell-study-note.md ├── jsp-servlet-sum.md ├── nju-ics2018-pa-note.md ├── patA1093.md ├── spring data pager.md └── think-in-java-notes.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /BATHM Exam/huawei1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | 6 | int len; 7 | char s[128]; 8 | char out[256][3]= {0}; 9 | 10 | scanf("%d", &len); 11 | char c[3]; 12 | int l = 0; 13 | int ll = 0; 14 | for (int i = 0; i < len - 1; i++) 15 | { 16 | scanf("%s", c); 17 | if (strlen(c) == 1) 18 | { 19 | if (c[0] == 'A') 20 | { 21 | out[l][0] = '1'; 22 | out[l][1] = '2'; 23 | out[l][2] = '\0'; 24 | l++; 25 | out[l][0] = '3'; 26 | out[l][1] = '4'; 27 | out[l][2] = '\0'; 28 | l++; 29 | } 30 | else if (c[0] == 'B') 31 | { 32 | out[l][0] = 'A'; 33 | out[l][1] = 'B'; 34 | out[l][2] = '\0'; 35 | l++; 36 | out[l][0] = 'C'; 37 | out[l][1] = 'D'; 38 | out[l][2] = '\0'; 39 | l++; 40 | } 41 | else { 42 | out[l][0] = c[0]; 43 | out[l][1] = '\0'; 44 | l++; 45 | } 46 | 47 | } 48 | else 49 | { 50 | out[l][0] = c[0]; 51 | out[l][1] = c[1]; 52 | out[l][2] = '\0'; 53 | l++; 54 | } 55 | 56 | } 57 | 58 | printf("%d ", l); 59 | for (int i = 0; i < l; i++) 60 | { 61 | printf("%s ", out[i]); 62 | } 63 | 64 | return 0; 65 | } -------------------------------------------------------------------------------- /PAT with C/PublicBikeADV1018.java: -------------------------------------------------------------------------------- 1 | package com.kkkk.patA; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * @author Yulin.Wang 7 | * @date 2019-07-28 8 | * @description 9 | **/ 10 | //TODO: 11 | 12 | public class PublicBikeADV1018 { 13 | 14 | final int INF = 99999; 15 | 16 | int c; 17 | int n; 18 | int sp; 19 | int edge; 20 | 21 | int[][] m; 22 | int[] cap; 23 | boolean[] visit; 24 | 25 | Stack[] pre; 26 | Stack path, temp; 27 | int minNeed = INF; 28 | int minRemain = INF; 29 | 30 | public int dijkstra(int s) { 31 | int[] d = new int[n+1]; 32 | Arrays.fill(d, INF); 33 | d[s] = 0; 34 | 35 | for (int i = 0; i <= n; i++) { 36 | int min = INF; 37 | int u = -1; // if s cant connect others 38 | for (int j = 0; j <= n; j++) { 39 | if (!visit[j] && d[j] < min) { 40 | u = j; 41 | min = d[j]; 42 | } 43 | } 44 | 45 | if (u == -1) { return 0; } //none of nodes could connect origin 46 | 47 | visit[u] = true; // node u ,visited. d[u] is minimal. 48 | for (int v = 0; v <= n; v++) { 49 | if (!visit[v] && m[u][v] != INF) {// just search unvisited node 50 | int cur = d[u] + m[u][v]; 51 | if (cur < d[v]) { 52 | d[v] = cur; 53 | pre[v].clear(); 54 | pre[v].push(u); 55 | } else if (cur == d[v]) { 56 | pre[v].push(u); // generate best path. 57 | } 58 | } 59 | } 60 | 61 | } 62 | return 1; 63 | } 64 | 65 | public void dfs(int station) { 66 | if (station == 0) { 67 | int need = 0, remain = 0; 68 | temp.push(station); 69 | 70 | for (int i = temp.size() - 1; i >= 0; i--) { 71 | int s = temp.get(i); 72 | if (cap[s] >= 0) { 73 | remain += cap[s]; 74 | } else { 75 | if (remain + cap[s] > 0) { // remain > abs(cap) 76 | remain += cap[s]; 77 | } else { 78 | need += 0 - cap[s] - remain; 79 | remain = 0; 80 | } 81 | } 82 | } 83 | if (need < minNeed) { // 1.shortest : depth first 2.min need 84 | minNeed = need; 85 | path = (Stack) temp.clone(); 86 | minRemain = remain; 87 | } else if (need == minNeed && remain < minRemain) { //3.min take from PBMC 88 | minRemain = remain; 89 | path = (Stack) temp.clone(); 90 | } 91 | temp.pop(); 92 | return; 93 | } 94 | temp.push(station); 95 | for (int i = 0; i < pre[station].size(); i++) { 96 | dfs(pre[station].get(i)); //depth first, search every prefix 97 | } 98 | temp.pop(); 99 | } 100 | 101 | public void init() { 102 | 103 | Scanner sc = new Scanner(System.in); 104 | c = sc.nextInt(); 105 | n = sc.nextInt(); // 0 is PBMC, NODE start from 1 to n 106 | sp = sc.nextInt(); 107 | edge = sc.nextInt(); 108 | 109 | m = new int[n+1][n+1]; 110 | cap = new int[n+1]; 111 | visit = new boolean[n+1]; 112 | Arrays.fill(visit, false); 113 | pre = new Stack[n+1]; 114 | for (int i = 0; i < n+1; i++) { 115 | pre[i] = new Stack<>(); 116 | } 117 | temp = new Stack<>(); 118 | path = new Stack<>(); 119 | 120 | for (int i = 1; i < n+1; i++) { 121 | cap[i] = sc.nextInt() - c/2; // simplify: capacity > half is positive 122 | } 123 | 124 | for (int i = 0; i <= n; i++) { 125 | Arrays.fill(m[i], INF); 126 | } 127 | 128 | for (int i = 0; i < edge; i++) { 129 | int s = sc.nextInt(); 130 | int e = sc.nextInt(); 131 | m[s][e] = sc.nextInt(); 132 | m[e][s] = m[s][e]; 133 | } 134 | } 135 | 136 | public void print() { 137 | System.out.print(minNeed + " "); 138 | for (int i = path.size() - 1; i >= 0; i--) { 139 | System.out.print(path.get(i).toString()); 140 | if (i > 0) System.out.print("->"); 141 | } 142 | System.out.print(" " + minRemain); 143 | } 144 | 145 | 146 | public static void main(String[] args) { 147 | 148 | PublicBikeADV1018 p = new PublicBikeADV1018(); 149 | p.init(); 150 | p.dijkstra(0); 151 | p.dfs(p.sp); 152 | p.print(); 153 | 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /PAT with C/patA1005.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // ** PAT A 1005 Spell it right 5 | // Given a non-negative integer N, your task is to compute the sum of all the digits of N, 6 | // and output every digit of the sum in English. 7 | 8 | // Input Specification: 9 | // Each input file contains one test case. Each case occupies one line which contains 10 | // an N (≤10^100). 11 | 12 | // Output Specification: 13 | // For each test case, output in one line the digits of the sum in English words. 14 | // There must be one space between two consecutive words, but no extra space at the end of a line. 15 | 16 | #define MAX 101 17 | 18 | char d[10][10] = {"zero", "one", "two", "three", "four", "five", 19 | "six", "seven", "eight", "nine"}; 20 | 21 | int main(void) { 22 | 23 | int s[5] = { 0 }; // digit 24 | char c; 25 | 26 | int sum = 0; 27 | while (scanf("%c", &c)) 28 | { 29 | if (c == '\n') break; 30 | sum += c - '0'; 31 | } 32 | 33 | if (sum == 0) 34 | { 35 | printf("zero"); 36 | return 0; 37 | } 38 | 39 | int x = 0; 40 | while (sum != 0) 41 | { 42 | s[x] = sum % 10; // 100 % 10 = 0 43 | sum = sum / 10; 44 | x++; 45 | } 46 | 47 | for (int i = x - 1; i >= 0; i--) 48 | { 49 | printf("%s", d[s[i]]); 50 | if (i != 0) printf(" "); 51 | } 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /PAT with C/patA1028.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // ** PAT A 1028 List Sorting 6 | 7 | // 字符串,数字,特定数字格式 的排序 8 | // ascend, non-desc, non-desc 9 | #define MAXN 100001 10 | int type; 11 | 12 | struct stu 13 | { 14 | int no; 15 | char s[9]; 16 | int g; 17 | }; 18 | 19 | int cmp(const void *a, const void *b) 20 | { 21 | // default ascend , >:1, =:0 , <:-1 22 | const struct stu *p = a; 23 | const struct stu *q = b; 24 | switch (type) 25 | { 26 | case 1: 27 | return p->no - q->no; 28 | case 2: 29 | { 30 | char a[9]; 31 | char b[9]; 32 | strcpy(a, p->s); 33 | strcpy(b, q->s); 34 | int la = strlen(a); 35 | int lb = strlen(b); 36 | for (int i = 0; (i < la|| i < lb); i++) 37 | { 38 | if (a[i] == b[i]) 39 | { 40 | continue; 41 | } 42 | else 43 | { 44 | return a[i] - b[i]; 45 | } 46 | } 47 | 48 | if (la == lb) 49 | { 50 | return p->no - q->no; 51 | } 52 | else 53 | { 54 | return la - lb; 55 | } 56 | } 57 | default://case 3 58 | { 59 | if (p->g == q->g) 60 | { 61 | return p->no - q->no; 62 | } 63 | else 64 | { 65 | return p->g - q->g; 66 | } 67 | } 68 | } 69 | } 70 | 71 | int main(void) { 72 | int n; 73 | 74 | scanf("%d %d", &n, &type); 75 | 76 | struct stu a[n]; 77 | int no, g; 78 | char str[9]; 79 | for (int i = 0; i < n; i++) 80 | { 81 | scanf("%d %s %d", &no, str, &g); //scanf 读字符串会补\0 82 | a[i].no = no; 83 | strcpy(a[i].s, str); 84 | a[i].g = g; 85 | } 86 | qsort(a, n, sizeof(a[0]), cmp); 87 | 88 | for(int i = 0; i < n; ++i) 89 | { 90 | printf("%06d %s %d\n", a[i].no, a[i].s, a[i].g); 91 | } 92 | 93 | return 0; 94 | } -------------------------------------------------------------------------------- /PAT with C/patA1032c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // ** PAT A 1032 Sharing 5 | //https://www.nowcoder.com/pat/5/problem/4019 6 | 7 | struct Node 8 | { 9 | int next; 10 | char flag; 11 | }; 12 | 13 | 14 | int main() 15 | { 16 | int s1, s2, n; 17 | scanf("%d%d%d", &s1, &s2, &n); 18 | 19 | struct Node data[100001]; 20 | char tmp; 21 | int addr, next; 22 | for (int i = 0; i < n; i++) 23 | { 24 | scanf("%d %c %d", &addr, &tmp, &next); 25 | data[addr].next = next; 26 | data[addr].flag = 0; 27 | } 28 | 29 | for (int i = s1; i != -1; i = data[i].next) 30 | { 31 | data[i].flag = 1; 32 | } 33 | 34 | int p; 35 | for (p = s2; p != -1; p = data[p].next) 36 | { 37 | if (data[p].flag == 1) 38 | break; 39 | } 40 | if (p != -1) 41 | { 42 | printf("%05d\n", p); 43 | } else { 44 | printf("%05d\n", -1); 45 | } 46 | return 0; 47 | } -------------------------------------------------------------------------------- /PAT with C/patA1042.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // ** PAT A 1042 shuffling machine 5 | 6 | // status of a card deck is in the following order: 7 | 8 | // S1, S2, ..., S13, 9 | // H1, H2, ..., H13, 10 | // C1, C2, ..., C13, 11 | // D1, D2, ..., D13, 12 | // J1, J2 13 | 14 | // Sample Input: 15 | // 2 16 | // 36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 17 | // 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47 18 | // Sample Output: 19 | // S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 20 | // D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 21 | // C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5 22 | 23 | /* 24 | * "S" stands for "Spade", "H" for"Heart", 25 | * "C" for "Club", "D" for"Diamond", and "J" for "Joker". 26 | */ 27 | 28 | #define MAX 55 29 | 30 | char s[5] = {'S', 'H', 'C', 'D', 'J'}; 31 | 32 | int main(void) { 33 | int rpe; 34 | int sh[MAX]; 35 | int card[MAX]; 36 | scanf("%d", &rpe); 37 | 38 | for (int i = 0; i < MAX - 1; i++) 39 | { 40 | scanf("%d", &sh[i]); 41 | card[i] = i + 1; 42 | } 43 | 44 | int temp[MAX]; 45 | for (int i = 0; i < rpe; i++) 46 | { 47 | for (int j = 0; j < MAX - 1; j++) 48 | { 49 | temp[sh[j] - 1] = card[j]; 50 | } 51 | for (int j = 0; j < MAX - 1; j++) 52 | { 53 | card[j] = temp[j]; 54 | } 55 | } 56 | 57 | for (int i = 0; i < MAX - 1; i++) 58 | { 59 | int a = card[i] - 1; 60 | printf("%c%d", s[a / 13], (a % 13) + 1); 61 | if (i != MAX - 2) printf(" "); 62 | } 63 | return 0; 64 | } -------------------------------------------------------------------------------- /PAT with C/patA1049.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // ** PAT A 1049 counting ones 5 | 6 | // The task is simple: given any positive integer N, you are supposed to count the 7 | // total number of 1's in the decimal form of the integers from 1 to N. 8 | // For example, given N being 12, there are five 1's in 1, 10, 11, and 12. 9 | 10 | // Input Specification: 11 | // Each input file contains one test case which gives the positive N (≤2^30) 12 | 13 | // Output Specification: 14 | // For each test case, print the number of 1's in one line. 15 | 16 | 17 | int main(void) { 18 | int n; 19 | scanf("%d", &n); 20 | 21 | int sum = 0; 22 | int a = 1; //power 23 | while (n / a != 0) 24 | { 25 | int num = n / a; 26 | int lo = n % a; 27 | int cur = num % 10; 28 | int hi = num / 10; 29 | 30 | if (cur == 0) 31 | { 32 | sum += hi * a; 33 | } 34 | else 35 | { 36 | sum += (cur == 1) ? (hi * a + lo + 1) : ((hi+1) * a); 37 | } 38 | a *= 10; 39 | } 40 | printf("%d\n", sum); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /PAT with C/patA1074.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAXN 100001 5 | 6 | struct node { 7 | int data; 8 | int next; 9 | }; 10 | 11 | int main(void) { 12 | struct node list[MAXN]; 13 | int first, n, k; 14 | int addr, data, next; 15 | 16 | memset(list, 0, MAXN * sizeof(struct node)); 17 | scanf("%d %d %d", &first, &n, &k); 18 | 19 | for(int i = 0; i < n; ++i) { 20 | scanf("%d %d %d", &addr, &data, &next); 21 | list[addr].data = data; 22 | list[addr].next = next; 23 | } 24 | 25 | int p = first; 26 | int c = 0; //calc valid node with -1 end( maybe multiple -1) 27 | while (p != -1) 28 | { 29 | p = list[p].next; 30 | c++; 31 | } 32 | 33 | n = c; // count of valid nodes 34 | c = 0; 35 | p = first; 36 | int head = first; 37 | int last = first; 38 | int suff = first; 39 | int cur = first; 40 | for (int i = 0; i < n / k; i++) // every k node 41 | { 42 | p = suff; 43 | while (c < k) // two pointer cur p reverse link 44 | { 45 | cur = suff; 46 | suff = list[cur].next; 47 | if (c > 0) 48 | { 49 | if (c == k - 1)// the k th one 50 | { 51 | if (i == 0) 52 | { 53 | head = cur; 54 | list[first].next = suff; 55 | first = suff; 56 | } 57 | else 58 | { 59 | list[last].next = cur; 60 | last = first; 61 | list[first].next = (suff == -1) ? -1 : suff; 62 | first = suff; 63 | } 64 | } 65 | list[cur].next = p; 66 | p = cur; 67 | } 68 | c++; 69 | } 70 | c = 0; 71 | } 72 | 73 | while (head != -1) 74 | { 75 | if (list[head].next == -1) 76 | { 77 | printf("%05d %d %d\n", head, list[head].data, -1); 78 | } 79 | else 80 | { 81 | printf("%05d %d %05d\n", head, list[head].data, list[head].next); 82 | } 83 | head = list[head].next; 84 | } 85 | 86 | return 0; 87 | } -------------------------------------------------------------------------------- /PAT with C/patA1093.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAXN 100002 5 | 6 | int main(void) { 7 | char s[MAXN]; 8 | unsigned char p[MAXN]; 9 | unsigned char t[MAXN]; 10 | memset(s, 0, MAXN * sizeof(char)); 11 | memset(p, 0, MAXN * sizeof(char)); 12 | memset(t, 0, MAXN * sizeof(char)); 13 | 14 | gets(s); 15 | int len = strlen(s); 16 | 17 | int lastP, lastT, c = 0; 18 | for (int i = 0; i < len; i++) 19 | { 20 | if (s[i] == 'A') 21 | { 22 | c++; 23 | p[c] = lastP + p[c - 1]; 24 | if (c > 1) { t[c - 1] = lastT; } 25 | lastT = 0; 26 | } 27 | 28 | if (s[i] == 'P') { lastP++; } 29 | if (s[i] == 'T') { lastT++; } 30 | } 31 | t[c] = lastT; 32 | 33 | int sum = 0; 34 | for (int i = 1; i <= c; i++) 35 | { 36 | sum += (p[i] * t[i]) % 1000000007; 37 | } 38 | 39 | printf("%d\n", sum); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /PAT with C/patB1001.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAX 199999 5 | 6 | int main() 7 | { 8 | 9 | int c = 1; 10 | int n = 0; 11 | int s = 0; 12 | int e = 0; 13 | scanf("%d %d", &s, &e); 14 | 15 | for(int i = 2; i <= MAX; i++) 16 | { 17 | int j = 2; 18 | 19 | if (s == 1 && i == 2) 20 | { 21 | printf("%d ", 2); 22 | if (e == 1) 23 | return 0; 24 | else 25 | continue; 26 | } 27 | 28 | for(j = 2; j <= (int)sqrt(i); j++) 29 | { 30 | if (i % j == 0) { 31 | j = 0; 32 | break; 33 | } 34 | } 35 | 36 | if (j != 0) { 37 | n++; 38 | if (n >= s) { 39 | if (n == e) 40 | { 41 | printf("%d", i); 42 | return 0; 43 | } 44 | if (c == 10) 45 | { 46 | printf("%d\n", i); 47 | c = 0; 48 | } 49 | else 50 | printf("%d ", i); 51 | c++; 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /PAT with C/patB1015.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAXN 100001 5 | 6 | struct stu 7 | { 8 | int no; 9 | int m; 10 | int t; 11 | int cg; 12 | }; 13 | 14 | int cmp(const void *a ,const void *b) 15 | { 16 | // default ascend , > 1 = 0 < -1 17 | const struct stu *p = a; 18 | const struct stu *q = b; 19 | 20 | if (p->cg == q->cg) 21 | { 22 | if((p->m + p->t) == (q->m + q->t)) 23 | { 24 | return (p->m == q->m) ? (p->no - q->no) : 0 - (p->m - q->m); 25 | } 26 | return 0 - (p->m + p->t - q->m - q->t); 27 | } 28 | return 0 - (p->cg - q->cg); 29 | } 30 | 31 | int main(void) { 32 | int n, low, high; 33 | 34 | scanf("%d %d %d", &n, &low, &high); 35 | 36 | struct stu a[n]; 37 | int no, m, t; 38 | int count = n; 39 | for (int i = 0; i < n; i++) 40 | { 41 | scanf("%d %d %d", &no, &m, &t); 42 | a[i].no = no; 43 | a[i].t = t; 44 | a[i].m = m; 45 | 46 | if (m < low || t < low) 47 | { 48 | a[i].cg = 0; 49 | count--; 50 | } 51 | else 52 | { 53 | if (m < high) 54 | { 55 | a[i].cg = (m >= t) ? 2 : 1; 56 | } 57 | else 58 | { 59 | a[i].cg = (t < high) ? 3 : 4; 60 | } 61 | } 62 | } 63 | qsort(a, n, sizeof(a[0]), cmp); 64 | 65 | printf("%d\n", count); 66 | for(int i = 0; i < count; ++i) 67 | { 68 | printf("%08d %d %d\n", a[i].no, a[i].m, a[i].t); 69 | } 70 | 71 | return 0; 72 | } -------------------------------------------------------------------------------- /PAT with C/patB1016.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAX 11 5 | 6 | void swap(char* a, char* b) 7 | { 8 | *a = *a ^ *b; 9 | *b = *b ^ *a; 10 | *a = *a ^ *b; 11 | } 12 | 13 | int main(void) { 14 | char s1[MAX]; 15 | char s2[MAX]; 16 | char s[MAX]; 17 | char a; 18 | char b; 19 | scanf("%s %c %s %c", s1, &a, s2, &b); 20 | memset(s, '\0', MAX * sizeof(char)); 21 | 22 | int c1 = 0; 23 | int c2 = 0; 24 | int len = (strlen(s1) > strlen(s2)) ? strlen(s1) : strlen(s2); 25 | for (int i = 0; i < len; i++) 26 | { 27 | if (s1[i] == a) c1++; 28 | if (s2[i] == b) c2++; 29 | } 30 | 31 | int c = (c1 > c2) ? c1 : c2; 32 | if (c == 0) 33 | { 34 | printf("%d\n", 0); 35 | return 0; 36 | } 37 | 38 | a -= '0'; 39 | b -= '0'; 40 | int co = 0; 41 | for (int i = 0; i < c; i++) // 倒序输出 42 | { 43 | if (c1 != 0 && c2 != 0) 44 | { 45 | if (a + b + co > 9) 46 | { 47 | s[i] = a + b + co - 10 + '0'; 48 | co = 1; 49 | } 50 | else 51 | { 52 | s[i] = a + b + co + '0'; 53 | co = 0; 54 | } 55 | c1--; 56 | c2--; 57 | } 58 | else 59 | { 60 | 61 | s[i] = (c1 > c2) ? a : b; 62 | if (s[i] + co > 9) 63 | { 64 | s[i] = '0'; 65 | co = 1; 66 | } 67 | else 68 | { 69 | s[i] += (co + '0'); 70 | co = 0; 71 | } 72 | } 73 | } 74 | if (co == 1) s[c] = '1'; 75 | 76 | c = strlen(s); 77 | for (int i = 0; i < strlen(s)/2; i++) 78 | { 79 | c--; 80 | swap(&s[c], &s[i]); 81 | } 82 | 83 | printf("%s\n", s); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /PAT with C/patB1025.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* insertion sort and merge sort */ 4 | int n; 5 | 6 | void printArray(int a[]) { 7 | 8 | for(int i = 0; i < n; i++) 9 | { 10 | printf("%d", a[i]); 11 | if(i < n - 1) printf(" "); 12 | } 13 | printf("\n"); 14 | } 15 | 16 | int isInsertionSort(int tmp[], int chg[]) { 17 | int flag = 0; 18 | 19 | for(int i = 0; i < n; i++) 20 | { 21 | int temp = tmp[i]; 22 | 23 | 24 | } 25 | return 0; 26 | } 27 | 28 | int main(int argc, char const *argv[]) 29 | { 30 | scanf("%d", &n); 31 | 32 | int origin[n]; 33 | int temp[n]; 34 | int chg[n]; 35 | 36 | for(int i = 0; i < n; i++) 37 | { 38 | scanf("%d", &origin[i]); 39 | temp[i] = origin[i]; 40 | } 41 | 42 | for(int i = 0; i < n; i++) 43 | { 44 | scanf("%d", &chg[i]); 45 | } 46 | if () 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /PAT with C/patB1026.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | int c1 = 0; 6 | int c2 = 0; 7 | scanf("%d %d", &c1, &c2); 8 | 9 | int h = (c2 - c1) / 360000; 10 | int m = ((c2 - c1) / 6000) - h*60; 11 | double s = ((c2 - c1) / 100.00) - h*3600 - m*60; 12 | int ss = round(s); 13 | 14 | printf("%02d:%02d:%02d\n", h, m, ss); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LESS TALK MORE CODE 2 | 3 | 4 | 这么多star让我受宠若惊,一般博客就不收集了,这里收集一些课程或者质量高的教程。 5 | 本文主要来源是阮一峰的每周分享,以及hackerNews趣贴,以及我自己的收集 6 | 7 | 我的目标就是尽量掌握第一手资料,第一手资料最正确,最真实,往往也最容易理解。程序员应该杜绝营销号加工的二手,三手信息,养成自己查资料的习惯。 8 | 9 | --- 10 | 2019年更新,notes文件夹下放一些笔记,和对技术,业界的思考,与博客同步。 11 | 学习玉伯,把Issues当博客用了,以后放点随笔进去。 12 | 13 | --- 14 | 2021年更新,博客我现在都用notion写了,不定期更新到github上。 15 | 16 | `PAT with C`放了自己的PAT题解,用PAT编号标了,C语言实现。 17 | 18 | `BATHM Exam`放了一些笔试题,本人比较懒,看心情更新。 19 | 20 | **英语内容会标注English** 21 | 22 | 坚持每周更新一下 23 | 24 | --- 25 | ## 个人速查笔记 26 | 27 | [Git命令笔记](./notes/git-shell-study-note.md) 28 | 29 | [ThinkinJava notes](./notes/think-in-java-notes.md) 30 | 31 | [MySQL quick](./notes/sql.md) 32 | 33 | 34 | ## Computer Science / 硬件 / 底层 35 | 36 | [虚拟内存探究,深入理解进程地址空间](http://blog.coderhuo.tech/2017/10/19/Virtual_Memory_summary/) 37 | 38 | [强力推荐南大这个计算机系统基础实验课!!!](https://nju-ics.gitbooks.io/ics2018-programming-assignment/content/) 39 | 40 | [逆向工程初学者教程| English](https://www.begin.re/) 41 | 42 | [从头教你写一个LISP编译器| English](http://www.buildyourownlisp.com/contents) 43 | 44 | [比较全的计算机系统教程| English](https://teachyourselfcs.com/#math) 45 | 46 | [嵌入式软件开发学习指南](https://www.crifan.com/files/doc/docbook/embedded_soft_dev/release/html/embedded_soft_dev.html#emb_dev_related_things) 47 | 48 | [数字摄像头怎么工作的| English](http://datagenetics.com/blog/may12018/index.html) 49 | 50 | [Introduction to Computer Organization with x86-64 Assembly Language GNU Linux](http://bob.cs.sonoma.edu/IntroCompOrg-x64/book.html) 51 | 52 | [x86架构操作系统内核的实现](http://wiki.0xffffff.org/) 53 | 这个教程比较系统且照顾初学者,要比做CMU, MIT的LAB容易一些,但是也有学习的价值。 54 | 55 | ## Linux 56 | 57 | [LFS project 也有中文项目| English](http://www.linuxfromscratch.org/lfs/) 58 | 59 | [Linux 系统管理的面试题| English](https://github.com/trimstray/test-your-sysadmin-skills) 60 | 61 | [命令行程序的基本原理](https://blog.twentytwotabs.com/the-smallest-bash-program-in-the-universe/) 62 | 63 | [7小时入门Linux视频,有操作有讲解|Youtube](https://www.youtube.com/watch?v=wBp0Rb-ZJak) 64 | 65 | ## Math / Algorithm 66 | 67 | [图解Git 很详细清晰](https://marklodato.github.io/visual-git-guide/index-zh-cn.html) 68 | 69 | [数据结构可视化| English](http://www.cs.usfca.edu/~galles/visualization/Algorithms.html) 70 | 71 | [D3 图论教程 | 可视化,非常直观| English](https://mrpandey.github.io/d3graphTheory/index.html) 72 | 73 | [15种你应该知道的回归类型 | English](https://www.listendata.com/2018/03/regression-analysis.html) 74 | 75 | [可视化解释Markrov Chain | English](http://setosa.io/ev/markov-chains/) 76 | 77 | [CS109 数据科学| English](http://cs109.github.io/2015/index.html) 78 | 79 | [cvpapers的数据集| English](http://www.cvpapers.com/datasets.html) 80 | 81 | [可汗学院 多元微积分| 主讲是3Blue1Brown,很深入浅出](https://www.khanacademy.org/math/multivariable-calculus) 82 | 83 | [机器学习经典论文收集](http://suanfazu.com/discussion/68) 84 | 85 | ## Distribute System & Database 86 | 87 | [MIT Distribute system 翻译](https://github.com/feixiao/Distributed-Systems) 88 | 89 | [交互式介绍区块链的一个电子书| English](https://blockchainhandbook.io/) 90 | 91 | [交互式SQL语言教程| English](https://selectstarsql.com/) 92 | 93 | [Stanford CS346 实现一个数据库| English](https://web.stanford.edu/class/cs346/2015/) 94 | 95 | [用C实现一个简易SQLite数据库| English](https://cstack.github.io/db_tutorial/) 96 | 97 | ## JAVA/C/GO/Rust 98 | 99 | 本人很讨厌c++,但是喜欢c,故删除cpp内容 100 | 101 | --- 102 | 103 | [go中文文档](https://go-zh.org/doc/) 104 | 105 | [从头教你写一个LISP编译器| English](http://www.buildyourownlisp.com/contents) 106 | 107 | [Doug lea 的jdk邮件列表,很多讨论JDK的第一手内容](http://cs.oswego.edu/pipermail/concurrency-interest/) 108 | 109 | ## 企业技术分享 110 | 111 | [美团技术](https://tech.meituan.com/) 112 | 113 | [阿里技术](https://www.zhihu.com/org/a-li-ji-zhu) 114 | 115 | [腾讯技术工程](https://www.zhihu.com/org/teng-xun-ji-zhu-gong-cheng) 116 | 117 | 118 | ## Android/Win/iOS 119 | 120 | [非常详细的Android菜鸟教程 | 2015版](http://www.runoob.com/w3cnote/android-tutorial-contents.html) 121 | 122 | [Android Handler机制](https://www.cnblogs.com/codingmyworld/archive/2011/09/12/2174255.html) 123 | 124 | [Android UI刷新机制](https://juejin.im/post/6844904084164575239) 125 | 126 | ## Web / 计算机网络 127 | 128 | [如何阅读 RFC?| English](https://web.archive.org/web/20180916071340/https://www.mnot.net/blog/2018/07/31/read_rfc) 129 | 130 | [从协议设计的顶层角度,总体上解释互联网协议的设计思想| English](https://www.destroyallsoftware.com/compendium/network-protocols?share_key=97d3ba4c24d21147) 131 | 132 | [巨齐全前端开发文档| English](http://devdocs.io) 133 | 134 | [系统设计入门](https://github.com/donnemartin/system-design-primer/blob/master/README-zh-Hans.md) 135 | 136 | [6.830 数据库系统 MIT course| English](http://db.csail.mit.edu/6.830/) 137 | 138 | [腾讯Alloyteam前端工具库](http://alloyteam.github.io/) 139 | 140 | [Web architecture| English](https://engineering.videoblocks.com/web-architecture-101-a3224e126947) 141 | 142 | [互联网历史文件| English](https://rscott.org/OldInternetFiles/) 143 | [早期互联网是没有DNS的,一个hosts记录了所有网站.] 144 | 145 | [DELL emc的网络基本功教程](https://www.dell.com/community/%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E8%AE%A8%E8%AE%BA%E5%8C%BA/%E7%BD%91%E7%BB%9C%E5%9F%BA%E6%9C%AC%E5%8A%9F%E7%B3%BB%E5%88%97-%E7%BB%86%E8%AF%B4%E7%BD%91%E7%BB%9C%E9%82%A3%E4%BA%9B%E4%BA%8B%E5%84%BF-3%E6%9C%8826%E6%97%A5%E6%9B%B4%E6%96%B0/m-p/7045185#831148) 146 | 147 | [java socket的实践](https://juejin.im/post/6844903630047281159) 148 | 149 | ### RFC索引 150 | 151 | [RFC1180.TCP Tutorial](https://tools.ietf.org/html/rfc1180) -------------------------------------------------------------------------------- /notes/Centos-Linux-quick.md: -------------------------------------------------------------------------------- 1 | # 常用Linux命令 - 自由速查表 2 | 3 | ## CentOS 4 | 5 | 1. 查看已打开的端口 # `netstat -anp` 6 | 用firewalld查看:`firewall-cmd --list-ports` 7 | 8 | 2. 查看想开的端口是否已开 # `firewall-cmd --query-port=666/tcp` 9 | 若此提示 FirewallD is not running 10 | 表示为不可知的防火墙 需要查看状态并开启防火墙 11 | 12 | 3. 查看防火墙状态 # `systemctl status firewalld` 13 | running 状态即防火墙已经开启 14 | dead 状态即防火墙未开启 15 | 4. 开启防火墙,# `systemctl start firewalld` 没有任何提示即开启成功 16 | 5. 开启防火墙 # `service firewalld start` 17 | 关闭防火墙 # `systemctl stop firewalld` 18 | centos7.3 上述方式可能无法开启,可以先`systemctl unmask firewalld.service` 19 | 然后 `systemctl start firewalld.service` 20 | 21 | 6. 查看想开的端口是否已开 `firewall-cmd --query-port=666/tcp` 提示no表示未开 22 | 7. 开永久端口号 `firewall-cmd --zone=public --add-port=666/tcp --permanent` 23 | **打开关闭后,重启服务才能生效** 24 | 25 | 8. 重新载入配置 `firewall-cmd --reload` 比如添加规则之后,需要执行此命令 26 | 9. 再次查看想开的端口是否已开 `firewall-cmd --query-port=666/tcp` 提示yes表示成功 27 | 10. 若移除端口 `firewall-cmd --permanent --remove-port=666/tcp` -------------------------------------------------------------------------------- /notes/SSH-SCP.md: -------------------------------------------------------------------------------- 1 | # SSH, SCP, FTP等协议相关 2 | 3 | ## SSH 4 | 5 | * 普通登录:`ssh root@111.111.11.11 -p 22` -p 指定端口 6 | 7 | * 密钥文件登录:`ssh -i key.pem root@192.168.2.100` 8 | 9 | * 服务器端ssh变化:需要重新刷新key文件:`ssh-keygen -R 192.1.x.x` 10 | 11 | 12 | ## SCP 13 | 14 | 15 | ## screen 16 | 17 | * screen 连接串口: 18 | 19 | 1 - 找到 usb设备串口 `ls /dev/tty.usbserial-*` 20 | 21 | 2 - `screen /dev/tty.usbserial-XXXX 115200` 115200是baud rate 22 | 23 | * screen reattach: `screen -r XXXX` 24 | 25 | * screen 查看: `screen -ls` 26 | 27 | * screen 退出: `ctrl + d + a` 28 | 29 | ## NC 30 | 31 | ## curl 32 | 33 | ## sftp 34 | -------------------------------------------------------------------------------- /notes/git-shell-study-note.md: -------------------------------------------------------------------------------- 1 | # git/shell 学习笔记 2 | 3 | 4 | ### 1. IDEA vcs 新建了git仓库,第一次push github时遇到push to origin/master was rejected 5 | 6 | **原因: 需要从远程仓库pull 一次** 7 | 8 | 先进入本地仓库目录 9 | 10 | ```bash 11 | git pull 12 | 13 | git pull origin master 14 | 15 | git pull origin master --allow-unrelated-histories 16 | ``` 17 | 18 | ### 2. docker 19 | 20 | 本地docker有一个debian,端口20022, 登录进去用`ssh -p 20022 ics@127.0.0.1` 21 | 要复制进去文件,`docker cp`不管用,只能用` scp -P 20022 xxx.txt ics@127.0.0.1:~` 22 | 23 | `scp -i xxx.pem xxx.jar root@47.100.xxx.xxx:~/web/` 密钥文件的scp命令 24 | -------------------------------------------------------------------------------- /notes/jsp-servlet-sum.md: -------------------------------------------------------------------------------- 1 | # JSP - Servlet - JDBC 相关复习 2 | 3 | 应对 WEB 考试用。。。 4 | --- 5 | ## Tomcat 配置 6 | 7 | conf 存放全局配置 8 | lib 存放全局站点共享的jar包 9 | webapps 默认站点根目录 10 | work 存放jsp,servlet等的编译结果 11 | 12 | 项目/WEB-INF/web.xml 项目的配置文件 13 | 14 | ## Java Server Page 15 | 16 | `<%@ page ... %>` jsp声明 17 | 18 | `<%@ include ... %>` 引入文件 19 | 20 | `<%@ taglib ... %>` 引入标签库 21 | 22 | ## DOM BOM 23 | 24 | Document Object Model - document.getElementByClassName... 25 | 26 | Browser Object Model - window.document, window.screen, window.history... 27 | 28 | 29 | ## HTML 30 | 31 | ```html 32 | 33 | 34 | xxxx 35 | 36 | ``` 37 | 38 | 在head中可定义网页标题的图标 -------------------------------------------------------------------------------- /notes/nju-ics2018-pa-note.md: -------------------------------------------------------------------------------- 1 | # NJU-ICS2018 课设笔记 2 | 3 | 虽然不是njuer,但是南大这套课程做得真不错,跟ivy接轨了,慕名做做,复习一下计算机体系。 4 | 5 | ## PA0 6 | 7 | 对我这种老油条来说,太简单了,mac下一路敲命令搞定,不过如果是windows应该会困难重重,看QA里说不少人windows下的docker有问题。果然程序员还是应该至少熟悉一种Unix类环境才行。 8 | 9 | 不过我也很理解助教烦躁的心情,因为学计算机与其他理工科不同的一点就是需要极大的折腾之心,纯理论是学不好计算机的,一定要坚持动手折腾。 10 | 11 | ## PA1 12 | 13 | ``` 14 | /* TODO: Re-organize the `CPU_state' structure to match the register 15 | * encoding scheme in i386 instruction format. For example, if we 16 | * access cpu.gpr[3]._16, we will get the `bx' register; if we access 17 | * cpu.gpr[1]._8[1], we will get the 'ch' register. Hint: Use `union'. 18 | * For more details about the register encoding scheme, see i386 manual. 19 | */ 20 | ``` 21 | 故意没设置好CPU的结构体,让你重新设置,考验c语言能力。 22 | 首先根据[i386手册](http://css.csail.mit.edu/6.858/2013/readings/i386.pdf),查看CPU寄存器的结构: 23 | ``` 24 | GENERAL REGISTERS 25 | 31 23 15 7 0 26 | ╔════════════════╪════════════════╬════════════════╧════════════════╗ 27 | ║ EAX AH AX AL ║ 28 | ╠════════════════╪════════════════╬════════════════╩════════════════╣ 29 | ║ EDX DH DX DL ║ 30 | ╠════════════════╪════════════════╬════════════════╩════════════════╣ 31 | ║ ECX CH CX CL ║ 32 | ╠════════════════╪════════════════╬════════════════╩════════════════╣ 33 | ║ EBX BH BX BL ║ 34 | ╠════════════════╪════════════════╬════════════════╩════════════════╣ 35 | ║ EBP BP ║ 36 | ╠════════════════╪════════════════╬════════════════╪════════════════╣ 37 | ║ ESI SI ║ 38 | ╠════════════════╪════════════════╬════════════════╪════════════════╣ 39 | ║ EDI DI ║ 40 | ╠════════════════╪════════════════╬════════════════╪════════════════╣ 41 | ║ ESP SP ║ 42 | ╚════════════════╪════════════════╬════════════════╪════════════════╝ 43 | ``` 44 | 也就是说要实现访问ax[12],ax[5]实际上就是访问eax[12],ah[5], C语言中union的各成员占用相同的内存空间,一个union的长度等于其最长的成员的长度,所以union就可以实现这种结构: 45 | 46 | ```c 47 | union { 48 | union { 49 | uint32_t _32; 50 | uint16_t _16; 51 | uint8_t _8[2]; 52 | } gpr[8]; 53 | 54 | struct { 55 | rtlreg_t eax; 56 | rtlreg_t ecx; 57 | rtlreg_t edx; 58 | rtlreg_t ebx; 59 | rtlreg_t esp; 60 | rtlreg_t ebp; 61 | rtlreg_t esi; 62 | rtlreg_t edi; 63 | }; 64 | }; 65 | ``` 66 | 67 | 这样访问`gpr[0]` 就是访问`eax;`,`gpr[1]._8[1]`就是`CH`. 68 | 69 | ```shell 70 | ics@8ae3ed6bab0b:~/ics2018/nemu$ make run 71 | ./build/nemu -l ./build/nemu-log.txt -d /home/ics/ics2018/nemu/tools/qemu-diff/build/qemu-so 72 | [src/monitor/monitor.c,54,load_default_img] No image is given. Use the default build-in image. 73 | [src/monitor/monitor.c,28,welcome] Debug: ON 74 | [src/monitor/monitor.c,31,welcome] If debug mode is on, A log file will be generated to record every instruction NEMU executes. This may lead to a large log file. If it is not necessary, you can turn it off in include/common.h. 75 | [src/monitor/monitor.c,36,welcome] Build time: 13:50:33, May 4 2019 76 | Welcome to NEMU! 77 | For help, type "help" 78 | ``` 79 | 80 | 运行成功,通过assert 81 | -------------------------------------------------------------------------------- /notes/patA1093.md: -------------------------------------------------------------------------------- 1 | # 近期算法心得 2 | 3 | ## PAT 甲级1093 4 | 5 | 刷题平台还是先选PAT,因为能顺便考个证书,熟练了转战LeetCode。 6 | 7 | 输入 8 | Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 9 | characters containing only P, A, or T. 10 | 11 | 输出: 12 | For each test case, print in one line the number of PAT's contained in the string. Since the result may be a huge number, you only have to 13 | output the result moded by 1000000007. 14 | 15 | 输入例子: 输出例子: 16 | APPAPT 2 17 | 18 | ## 分析 19 | 20 | 思路1:将每个A左边的P的个数乘以右边的T的个数,最后加起来,即是答案。 21 | 22 | 实现起来较麻烦,需要1或2个数组存P和T,时间复杂度O(n)。 23 | 24 | 思路2:PAT的个数 += PA的个数 += P的个数 25 | 26 | 用代码一看就知: 27 | ```c 28 | while(scanf("%c", &c) && c!='\n') 29 | { 30 | if (c == 'P') 31 | { 32 | p++; 33 | } 34 | if (c == 'A') 35 | { 36 | pa += p; 37 | pa = pa % 1000000007; 38 | } 39 | if (c == 'T') 40 | { 41 | pat += pa; 42 | pat = pat % 1000000007; 43 | } 44 | } 45 | printf("%d\n", pat); 46 | ``` 47 | -------------------------------------------------------------------------------- /notes/spring data pager.md: -------------------------------------------------------------------------------- 1 | 2 | # 记spring data page分页器的一个小坑 3 | 4 | 问题倒也不难,但是比较绕,记录一下。 5 | 6 | 做的项目有用到 Spring data的分页器,本来应该在JpaReposity里就直接生成page的。但是情况特殊,有时候要转换现成的list来分页,于是我的需求是这样的: 7 | 8 | ```java 9 | List ulist = userService.findAllUser(); 10 | Pageable pageable = PageRequest.of(0, 5, Sort.Direction.ASC,"id"); 11 | Page datas = new PageImpl<>(clist, pageable, clist.size()); 12 | ``` 13 | 要传一个9个元素的list给page,page为第一页,每页5条。 14 | 看一下doc: 15 | ```java 16 | public static PageRequest of(int page,int size,Sort.Direction direction,String... properties) 17 | 18 | Creates a new PageRequest with sort direction and properties applied. 19 | Parameters: 20 | page - zero-based page index. 21 | size - the size of the page to be returned. 22 | ``` 23 | 很好,没毛病,page 0, size 5。 24 | >public PageImpl(List content, Pageable pageable, long total) 25 | 26 | page的实现类,Constructor of PageImpl.乍看也没什么毛病,直接编译运行,页确实给我分了两页,index也是第0页,然而第0页却显示了9条!很烦,前端分页器的totalPages 和getNumber()都是对的,就是不明白为什么给分了整个list。 27 | 28 | 首先,看源码: 29 | pageable的实现没什么问题,从运行结果看也不是什么问题,然后看pageimpl的: 30 | ```java 31 | public PageImpl(List content, Pageable pageable, long total) { 32 | 33 | super(content, pageable); 34 | 35 | this.total = pageable.toOptional().filter(it -> !content.isEmpty())// 36 | .filter(it -> it.getOffset() + it.getPageSize() > total)// 37 | .map(it -> it.getOffset() + content.size())// 38 | .orElse(total); 39 | } 40 | ``` 41 | 看了下注释,total是总数啊,虽然不明白这些断言是什么。。 42 | 43 | https://stackoverflow.com/questions/26720768/spring-data-pageimpl-not-returning-page-with-the-correct-size 44 | 45 | https://stackoverflow.com/questions/39930897/springdata-pageimpl-totalelements-is-wrong 46 | 47 | 上网一搜,不少人跟我一样,不过他们要么建议用pagelistholder,要么也没说清楚怎么回事。直到我看到这个: 48 | https://stackoverflow.com/questions/45740722/spring-data-page-gettotalelements-is-incorrect-on-the-last-page 49 | 50 | 于是我找到spring data commons的[github项目](https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/domain/PageImpl.java) 51 | ```java 52 | /** 53 | * Constructor of {@code PageImpl}. 54 | @param content the content of this page, must not be {@literal null}. 55 | @param pageable the paging information, must not be {@literal null}. 56 | @param total the total amount of items available. The total might be adapted considering the length of the content given, if it is going to be the content of the last page. This is in place to mitigate inconsistencies. 57 | */ 58 | ``` 59 | 考验英文阅读的细节了,再结合pageimpl的源码终于明白了,只是一场误会。 60 | 61 | springdata早期版本只是`this.total = total`, 后面为了解决最后一页显示条数的特殊性加了一些断言,`.map(it -> it.getOffset() + content.size())`先判断为不为空,然后判断offset,也就是当前page* page.size 大不大于total。大于说明是最后一页,然后会显示所传content的所有内容。 62 | 63 | **也就是说total确实是list.size(),但是content要传的是你这一页要显示的sublist!** 64 | 65 | 正确做法: 66 | ```java 67 | int start = page * size; //当前条目偏移 68 | int end = (start + size) > list.size() ? list.size() : (start + size);//判断是不是最后一页 69 | Page data = new PageImpl<>(list.subList(start, end), pageable, list.size()); 70 | ``` 71 | 72 | 一不小心就糊涂了,还是得仔细看说明文档。但是这种设计也是够sb的,参数说明应该清楚一点啊 73 | 74 | -------------------------------------------------------------------------------- /notes/think-in-java-notes.md: -------------------------------------------------------------------------------- 1 | # think in java Notes 2 | --- 3 | 4 | 5 | *Page 63* 6 | >1 This can be a flashpoint. There are those who say, “Clearly, it’s a pointer,” but this presumes an underlying implementation. Also, Java references are much more akin to C++ references than to pointers in their syntax. In the 1st edition of this book, I chose to invent a new term, “handle,” because C++ references and Java references have some important differences. I was coming out of C++ and did not want to confuse the C++ programmers whom I assumed would be the largest audience for Java. In the 2nd edition, I decided that “reference” was the more commonly used term, and that anyone changing from C++ would have a lot more to cope with than the terminology of references, so they might as well jump in with both feet. However, there are people who disagree even with the term “reference.” I read in one book where it was “completely wrong to say that Java supports pass by reference,” because Java object identifiers (according to that author) are actually “object references.” And (he goes on) everything is actually pass by value. So you’re not passing by reference, you’re “passing an object reference by value.” One could argue for the precision of such convoluted explanations, but I think my approach simplifies the understanding of the concept without hurting anything (well, the language lawyers may claim that I’m lying to you, but I’ll say that I’m providing an appropriate abstraction). 7 | 8 | 9 | 10 | >1. Registers.Thisisthefasteststoragebecauseitexistsinaplacedifferentfromthatof other storage: inside the processor. However, the number of registers is severely limited, so registers are allocated as they are needed. You don’t have direct control, nor do you see any evidence in your programs that registers even exist (C & C++, on the other hand, allow you to suggest register allocation to the compiler). 11 | 12 | >2. The stack. This lives in the general random-access memory (RAM) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create new memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack. 13 | 14 | >3. Theheap.Thisisageneral-purposepoolofmemory(alsointheRAMarea)whereall Java objects live. The nice thing about the heap is that, unlike the stack, the compiler doesn’t need to know how long that storage must stay on the heap. Thus, there’s a great deal of flexibility in using storage on the heap. Whenever you need an object, you simply write the code to create it by using new, and the storage is allocated on the heap when that code is executed. Of course there’s a price you pay for this flexibility: It may take more time to allocate and clean up heap storage than stack storage (if you even could create objects on the stack in Java, as you can in C++). 15 | 16 | >4. Constantstorage.Constantvaluesareoftenplaceddirectlyintheprogramcode, which is safe since they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM), in embedded systems. 17 | 18 | >5. Non-RAMstorage. 19 | >Ifdatalivescompletelyoutsideaprogram,itcanexistwhilethe program is not running, outside the control of the program. The two primary examples of this are streamed objects, in which objects are turned into streams of bytes, generally to be sent to another machine, and persistent objects, in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into a regular RAM- based object when necessary. Java provides support for lightweight persistence, and mechanisms such as JDBC and Hibernate provide more sophisticated support for storing and retrieving object information in databases. 20 | `` --------------------------------------------------------------------------------