diff --git a/GESP/GESP12月C++二级真题.pdf b/GESP/GESP12月C++二级真题.pdf index 11afe06..3b35aff 100644 Binary files a/GESP/GESP12月C++二级真题.pdf and b/GESP/GESP12月C++二级真题.pdf differ diff --git a/GESP/新文件1.cpp b/GESP/新文件1.cpp new file mode 100644 index 0000000..9248b3d --- /dev/null +++ b/GESP/新文件1.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (j == 1 || j == n) + cout << "|"; + else if (i == n / 2 + 1) + cout << "-"; + else + cout << "a"; + } + puts(""); + } + return 0; +} \ No newline at end of file diff --git a/TangDou/LuoGuBook/P1554.cpp b/TangDou/LuoGuBook/P1554.cpp index dd79a82..5ca4f6e 100644 --- a/TangDou/LuoGuBook/P1554.cpp +++ b/TangDou/LuoGuBook/P1554.cpp @@ -2,19 +2,19 @@ using namespace std; const int N = 11; -int a[N]; +int b[N]; int main() { int m, n; cin >> m >> n; - for (int i = m; i <= n; i++) { - int t = i; + for (int x = m; x <= n; x++) { + int t = x; while (t) { - int c = t % 10; - a[c]++; + int a = t % 10; + b[a]++; t /= 10; } } - for (int i = 0; i <= 9; i++)cout << a[i] << " "; + for (int i = 0; i <= 9; i++) cout << b[i] << " "; return 0; } \ No newline at end of file diff --git a/TangDou/LuoGuBook/P1614.cpp b/TangDou/LuoGuBook/P1614.cpp index 25b0a0e..5e94657 100644 --- a/TangDou/LuoGuBook/P1614.cpp +++ b/TangDou/LuoGuBook/P1614.cpp @@ -3,18 +3,20 @@ using namespace std; const int N = 3010; const int INF = 0x3f3f3f3f; -typedef long long LL; -int a[N]; -LL MIN = INF; +int s[N], a[N]; +int n, m; +int mi = INF; + int main() { - int n, m; cin >> n >> m; - for (int i = 1; i <= n; i++) cin >> a[i]; - for (int i = 1; i <= n - m + 1; i++) { - LL sum = 0; - for (int j = 0; j < m; j++) sum += a[i + j]; - MIN = min(MIN, sum); + for (int i = 1; i <= n; i++) { + cin >> a[i]; // 刺痛值 + s[i] = s[i - 1] + a[i]; // 构建一维前缀和 } - cout << MIN << endl; + + for (int i = m; i <= n; i++) + mi = min(mi, s[i] - s[i - m]); // 求定区间和并取最小的一部分 + // 输出最小值 + printf("%d", mi); return 0; } \ No newline at end of file diff --git a/TangDou/LuoGuBook/P1614_2.cpp b/TangDou/LuoGuBook/P1614_2.cpp deleted file mode 100644 index a3e47b2..0000000 --- a/TangDou/LuoGuBook/P1614_2.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include - -using namespace std; -const int N = 3010; -int a[N]; -int MIN; - -int main() { - //滑动窗口思想 - int n, m; - cin >> n >> m; - for (int i = 1; i <= n; i++) cin >> a[i]; - - //第一组m个数 - int sum = 0; - for (int i = 1; i <= m; i++) sum += a[i]; - MIN = sum;//第一组数的和是默认值 - - //滑动窗口,加入下一个数字,减去顶部的数字 - for (int i = m + 1; i <= n; i++) { - sum = sum + a[i] - a[i - m]; - //不断的取min,找出和的最小值 - MIN = min(MIN, sum); - } - //输出最小值 - printf("%d", MIN); - return 0; -} \ No newline at end of file diff --git a/TangDou/LuoGuBook/P1614_3.cpp b/TangDou/LuoGuBook/P1614_3.cpp deleted file mode 100644 index c3acf82..0000000 --- a/TangDou/LuoGuBook/P1614_3.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; -const int N = 3010; -const int INF = 0x3f3f3f3f; -int s[N], a[N]; -int n, m; -int MIN = INF; - -int main() { - cin >> n >> m; - for (int i = 1; i <= n; i++) { - cin >> a[i];//刺痛值 - s[i] = s[i - 1] + a[i];//构建一维前缀和 - } - - for (int i = m; i <= n; i++) - MIN = min(MIN, s[i] - s[i - m]);//求定区间和并取最小的一部分 - //输出最小值 - printf("%d", MIN); - return 0; -} \ No newline at end of file diff --git a/TangDou/LuoGuBook/P2141.cpp b/TangDou/LuoGuBook/P2141.cpp index ed95fc8..915d60a 100644 --- a/TangDou/LuoGuBook/P2141.cpp +++ b/TangDou/LuoGuBook/P2141.cpp @@ -1,22 +1,21 @@ #include using namespace std; -//这题30分的一般都是没有去重……1+4=5和2+3=5算同一个…… -//这道题还是挺有意思的,注意,前方有坑!需要理解 5=1+4=2+3,但5只算一次的道理。 const int N = 110; int n; int a[N]; -bool b[N]; //标识已使用 +bool b[N]; int cnt; int main() { cin >> n; - for (int i = 1; i <= n; i++)cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> a[i]; - //暴力三层循环+标识数组 - for (int i = 1; i < n; i++) - for (int j = i + 1; j <= n; j++) - for (int k = 1; k <= n; k++) + // c=a+b + for (int i = 1; i < n; i++) // 枚举两个数加法中的a,是小的那个 + for (int j = i + 1; j <= n; j++) // 枚举两个数加法中的b,是大的那个 + + for (int k = 1; k <= n; k++) // 枚举结果数c if (a[k] == a[i] + a[j] && !b[k]) cnt++, b[k] = true; printf("%d", cnt); diff --git a/TangDou/LuoGuBook/TD copy.cpp b/TangDou/LuoGuBook/TD copy.cpp new file mode 100644 index 0000000..b005b99 --- /dev/null +++ b/TangDou/LuoGuBook/TD copy.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; +int main() { + int x = 15; + vector path; // 动态数组 + while (x) { + int a = x % 2; + path.push_back(a); + x /= 2; + } + for (int i = path.size() - 1; i >= 0; i--) + cout << path[i]; + return 0; +} \ No newline at end of file diff --git a/TangDou/LuoGuBook/TD.cpp b/TangDou/LuoGuBook/TD.cpp index 13efd99..d1c5e9e 100644 --- a/TangDou/LuoGuBook/TD.cpp +++ b/TangDou/LuoGuBook/TD.cpp @@ -1,27 +1,18 @@ #include using namespace std; -int L; -int sum; // 已经放到口袋里的数字和 -// 检查数字是不是质数 -bool isPrime(int n) { - if (n < 2) return false; - for (int i = 2; i <= n / i; i++) - if (n % i == 0) return false; - return true; -} -int cnt; int main() { - cin >> L; - for (int i = 2;; i++) { - if (isPrime(i)) { - if (sum + i <= L) { - cout << i << endl; - cnt++; - sum = sum + i; - } else - break; - } + int x = 255; // FF + vector path; // 动态数组 + while (x) { + int a = x % 16; + path.push_back(a); + x /= 16; + } + for (int i = path.size() - 1; i >= 0; i--) { + if (path[i] < 10) + cout << path[i]; + else + printf("%c", 'A' + (path[i] - 10)); } - cout << cnt << endl; return 0; } \ No newline at end of file