From 41c78088e536648a86b072da6eba860ad271b125 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Fri, 29 Oct 2021 14:47:04 +0800 Subject: [PATCH] update exercises --- .../solution.md" | 110 +++++++++++++++++- .../solution.md" | 56 ++++++++- .../solution.md" | 70 ++++++++++- .../config.json" | 6 - .../desc.md" | 2 - .../solution.cpp" | 0 .../solution.java" | 24 ---- .../solution.md" | 34 ------ 8 files changed, 228 insertions(+), 74 deletions(-) delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.md" diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.md" index b3116ebd8..96dd47dc1 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\347\261\273\350\256\241\346\225\260/solution.md" @@ -26,7 +26,8 @@ ## aop ### before ```cpp - +#include +using namespace std; ``` ### after ```cpp @@ -35,21 +36,122 @@ ## 答案 ```cpp +int main(int argc, char **argv) +{ + string str; + cin >> str; + int A = 0, a = 0, number = 0; + int len = str.length(); + for (int i = 0; i < len; i++) + { + if (str[i] <= '9' && str[i] >= '0') + { + number++; + } + if (str[i] <= 'Z' && str[i] >= 'A') + { + A++; + } + if (str[i] <= 'z' && str[i] >= 'a') + { + a++; + } + } + cout << A << endl; + cout << a << endl; + cout << number << endl; + return 0; +} ``` ## 选项 ### A ```cpp - +int main(int argc, char **argv) +{ + string str; + cin >> str; + int A = 0, a = 0, number = 0; + int len = str.length(); + for (int i = 0; i < len; i++) + { + if (str[i] < '9' && str[i] > '0') + { + number++; + } + if (str[i] < 'Z' && str[i] > 'A') + { + A++; + } + if (str[i] < 'z' && str[i] > 'a') + { + a++; + } + } + cout << A << endl; + cout << a << endl; + cout << number << endl; + return 0; +} ``` ### B ```cpp - +int main(int argc, char **argv) +{ + string str; + cin >> str; + int A = 0, a = 0, number = 0; + int len = str.length(); + for (int i = 0; i < len; i++) + { + if (str[i] < 71 && str[i] > 60) + { + number++; + } + if (str[i] < 132 && str[i] > 101) + { + A++; + } + if (str[i] < 172 && str[i] > 141) + { + a++; + } + } + cout << A << endl; + cout << a << endl; + cout << number << endl; + return 0; +} ``` ### C ```cpp - +int main(int argc, char **argv) +{ + string str; + cin >> str; + int A = 0, a = 0, number = 0; + int len = str.length(); + for (int i = 0; i < len; i++) + { + if (str[i] < 39 && str[i] > 30) + { + number++; + } + if (str[i] < 132 && str[i] > 101) + { + A++; + } + if (str[i] <= 'z' && str[i] >= 'a') + { + a++; + } + } + cout << A << endl; + cout << a << endl; + cout << number << endl; + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.md" index 3431e59ff..047b2d12c 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\210\206\351\205\215\345\217\243\347\275\251/solution.md" @@ -14,30 +14,80 @@ masks = [9090400, 8499400, 5926800, 8547000, 4958200, 4422600, 5751200, 4175600, ## aop ### before ```cpp +#include +#include +#include +using namespace std; +long int masks[15] = {9090400, 8499400, 5926800, 8547000, 4958200, + 4422600, 5751200, 4175600, 6309600, + 5865200, 6604400, 4635000, 10663400, 8087200, 4554000}; +long ans = 1000000000; ``` ### after ```cpp +int main() +{ + dfs(0, 0, 0); + cout << ans; +} ``` ## 答案 ```cpp +void dfs(int n, long h1, long h2) +{ + if (n == 15) + { + ans = min(ans, abs(h1 - h2)); + return; + } + dfs(n + 1, h1 + masks[n], h2); + dfs(n + 1, h1, h2 + masks[n]); +} ``` ## 选项 ### A ```cpp - +void dfs(int n, long h1, long h2) +{ + if (n == 15) + { + ans = min(ans, abs(h1 - h2)); + return; + } + dfs(n + 1, h1 + masks[n + 1], h2); + dfs(n + 1, h1, h2 + masks[n + 1]); +} ``` ### B ```cpp - +void dfs(int n, long h1, long h2) +{ + if (n == 15) + { + ans = min(ans, abs(h1 - h2)); + return; + } + dfs(n + 1, h1 + masks[n + 1], h2); + dfs(n + 1, h1, h2 + masks[n]); +} ``` ### C ```cpp - +void dfs(int n, long h1, long h2) +{ + if (n == 15) + { + ans = min(ans, abs(h1 - h2)); + return; + } + dfs(n, h1 + masks[n], h2); + dfs(n, h1, h2 + masks[n]); +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.md" index a13e04477..ff697d7a2 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221/solution.md" @@ -30,7 +30,7 @@ Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。 ## aop ### before ```cpp - +#include ``` ### after ```cpp @@ -39,21 +39,89 @@ Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。 ## 答案 ```cpp +int main() +{ + int n, b; + scanf("%d", &n); + int a[n]; + a[0] = a[1] = 1; + for (int i = 2; i < n; i++) + { + a[i] = (a[i - 1] + a[i - 2]) % 10007; + b = a[i]; + } + if (n > 2) + printf("%d", b); + else + printf("1"); + return 0; +} ``` ## 选项 ### A ```cpp +int main() +{ + int n, b; + scanf("%d", &n); + int a[n]; + a[0] = a[1] = 1; + for (int i = 2; i < n; i++) + { + a[i] = (a[i - 1] + a[i - 2]) % 10007; + b = a[i] + 1; + } + if (n > 2) + printf("%d", b); + else + printf("1"); + return 0; +} ``` ### B ```cpp +int main() +{ + int n, b; + scanf("%d", &n); + int a[n]; + a[0] = a[1] = 1; + for (int i = 2; i < n; i++) + { + a[i] = (a[i - 1] + a[i - 2]) % 10007; + b = a[i - 1]; + } + if (n > 2) + printf("%d", b); + else + printf("1"); + return 0; +} ``` ### C ```cpp +int main() +{ + int n, b; + scanf("%d", &n); + int a[n]; + a[0] = a[1] = 1; + for (int i = 2; i < n; i++) + { + a[i] = (a[i - 1] + a[i - 2]) % 10007; + b = a[i - 2]; + } + if (n > 2) + printf("%d", b); + else + printf("1"); + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" deleted file mode 100644 index 2dddfe962..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/desc.md" +++ /dev/null @@ -1,2 +0,0 @@ -#### 问题描述 -斐波那契数列满足 F1 = F2 = 1,从 F3 开始有 Fn = Fn−1 + Fn−2。请你计算 GCD(F2020, F520),其中 GCD(A, B) 表示 A 和 B 的最大公约数。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" deleted file mode 100644 index 6641fde72..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.java" +++ /dev/null @@ -1,24 +0,0 @@ - -import java.math.BigInteger; - -public class BigNumber { - public static void main(String[] args) { - BigInteger a = new BigInteger("1"); - BigInteger b = new BigInteger("1"); - BigInteger[] fib = new BigInteger[2030]; - fib[1] = a; - fib[2] = b; - for (int x = 3; x < fib.length; x++) { - fib[x] = fib[x - 1].add(fib[x - 2]); - } - a = fib[2020]; - b = fib[520]; - BigInteger temp; - while (b != BigInteger.ZERO) { - temp = a.mod(b); - a = b; - b = temp; - } - System.out.println(a); - } -} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.md" deleted file mode 100644 index bea7b7285..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227\346\234\200\345\244\247\345\205\254\347\272\246\346\225\260/solution.md" +++ /dev/null @@ -1,34 +0,0 @@ -# 斐波那契数列最大公约数 -#### 问题描述 -斐波那契数列满足 F1 = F2 = 1,从 F3 开始有 Fn = Fn−1 + Fn−2。请你计算 GCD(F2020, F520),其中 GCD(A, B) 表示 A 和 B 的最大公约数。 - -## aop -### before -```cpp - -``` -### after -```cpp - -``` - -## 答案 -```cpp - -``` -## 选项 - -### A -```cpp - -``` - -### B -```cpp - -``` - -### C -```cpp - -``` -- GitLab