From cb17a48cc9408359aa25784e6b1bc3cbd3531392 Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Sat, 22 Mar 2025 20:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E6=9A=A8=E5=A4=A7?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=9C=BA=E5=A4=8D=E8=AF=95=E7=9A=84=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9C=9F=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2014冒泡排序.cpp | 32 ++++++++++++++++++++++++++++++ 2014矩形覆盖.cpp | 28 +++++++++++++++++++++++++++ 2014砍树修路.cpp | 31 +++++++++++++++++++++++++++++ 2015元音处理.cpp | 28 +++++++++++++++++++++++++++ 2015高精度乘法.cpp | 22 +++++++++++++++++++++ 2016字符统计.cpp | 28 +++++++++++++++++++++++++++ 2016猜数字.cpp | 31 +++++++++++++++++++++++++++++ 2017成绩排名.cpp | 32 ++++++++++++++++++++++++++++++ 2017数塔路径.cpp | 31 +++++++++++++++++++++++++++++ 2017计算第几天.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ 2018偶数分解.cpp | 25 ++++++++++++++++++++++++ 2018斐波那契数列.cpp | 22 +++++++++++++++++++++ 2018最大子序列的和.cpp | 41 +++++++++++++++++++++++++++++++++++++++ 2018蛇形矩阵.cpp | 23 ++++++++++++++++++++++ 2019判断回文串.cpp | 26 +++++++++++++++++++++++++ 2019格子涂色.cpp | 23 ++++++++++++++++++++++ 2019递增子序列最大和.cpp | 38 ++++++++++++++++++++++++++++++++++++ 2019递归求阶乘.cpp | 18 +++++++++++++++++ 2023成绩排名.cpp | 29 +++++++++++++++++++++++++++ 2023括号匹配.cpp | 29 +++++++++++++++++++++++++++ 2023斐波那契数.cpp | 24 +++++++++++++++++++++++ 2023求个位数.cpp | 18 +++++++++++++++++ 2024二元素数组.cpp | 25 ++++++++++++++++++++++++ 2024体重排序.cpp | 33 +++++++++++++++++++++++++++++++ 2024删除区间.cpp | 36 ++++++++++++++++++++++++++++++++++ 2024逆序对的数量.cpp | 28 +++++++++++++++++++++++++++ 26 files changed, 743 insertions(+) create mode 100644 2014冒泡排序.cpp create mode 100644 2014矩形覆盖.cpp create mode 100644 2014砍树修路.cpp create mode 100644 2015元音处理.cpp create mode 100644 2015高精度乘法.cpp create mode 100644 2016字符统计.cpp create mode 100644 2016猜数字.cpp create mode 100644 2017成绩排名.cpp create mode 100644 2017数塔路径.cpp create mode 100644 2017计算第几天.cpp create mode 100644 2018偶数分解.cpp create mode 100644 2018斐波那契数列.cpp create mode 100644 2018最大子序列的和.cpp create mode 100644 2018蛇形矩阵.cpp create mode 100644 2019判断回文串.cpp create mode 100644 2019格子涂色.cpp create mode 100644 2019递增子序列最大和.cpp create mode 100644 2019递归求阶乘.cpp create mode 100644 2023成绩排名.cpp create mode 100644 2023括号匹配.cpp create mode 100644 2023斐波那契数.cpp create mode 100644 2023求个位数.cpp create mode 100644 2024二元素数组.cpp create mode 100644 2024体重排序.cpp create mode 100644 2024删除区间.cpp create mode 100644 2024逆序对的数量.cpp diff --git a/2014冒泡排序.cpp b/2014冒泡排序.cpp new file mode 100644 index 0000000..9a86eab --- /dev/null +++ b/2014冒泡排序.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n,temp; + cin >> n; + vector array; + + for (int i = 0; i < n; i++) { + cin >> temp; + array.push_back(temp); + } + + for (int i = 0; i < n; i++) { + for(int j = 0;j < n - 1;j++){ + if(array[j] > array[j + 1]){ + temp = array[j + 1]; + array[j + 1] = array[j]; + array[j] = temp; + } + } + } + + for(auto i: array){ + cout << i << " "; + } + + return 0; +} diff --git a/2014矩形覆盖.cpp b/2014矩形覆盖.cpp new file mode 100644 index 0000000..f33ed15 --- /dev/null +++ b/2014矩形覆盖.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int m,n,a; + cin >> m >> n >> a; + + if(m%a == 0){ + m = m/a; + } + else{ + m = m/a + 1; + } + + if(n%a == 0){ + n = n/a; + } + else{ + n = n/a + 1; + } + + cout << m*n; + + return 0; +} diff --git a/2014砍树修路.cpp b/2014砍树修路.cpp new file mode 100644 index 0000000..feb0b23 --- /dev/null +++ b/2014砍树修路.cpp @@ -0,0 +1,31 @@ +#include +#include + +using namespace std; + +int main(){ + int L; + cin >> L; + int n; + cin >> n; + int a,b; + + vector route(L + 1,1); + + for(int i = 0;i < n;i++){ + cin >> a >> b; + for(int j = a;j <= b;j++){ + route[j] = 0; + } + } + + int counter = 0; + + for(auto i:route){ + counter += i; + } + + cout << counter; + + return 0; +} diff --git a/2015元音处理.cpp b/2015元音处理.cpp new file mode 100644 index 0000000..dd04f54 --- /dev/null +++ b/2015元音处理.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace std; + +int main(){ + string str; + cin >> str; + + for(auto i:str){ + switch(i){ + case 'a':case 'o':case 'e':case 'i':case 'u': + case 'A':case 'O':case 'E':case 'I':case 'U': + break; + default: + cout << '.'; + if(i < 92){ + printf("%c",i+32); + } + else{ + printf("%c",i-32); + } + } + } + + return 0; +} diff --git a/2015高精度乘法.cpp b/2015高精度乘法.cpp new file mode 100644 index 0000000..bff99e5 --- /dev/null +++ b/2015高精度乘法.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +using namespace std; + +int main(){ + string str; + vector num1,num2; + + cin >> str; + for(auto i:str){ + num1.push_back(stoi(&i)); + } + cin >> str; + for(auto i:str){ + num2.push_back(stoi(&i)); + } + + + return 0; +} diff --git a/2016字符统计.cpp b/2016字符统计.cpp new file mode 100644 index 0000000..54b2055 --- /dev/null +++ b/2016字符统计.cpp @@ -0,0 +1,28 @@ +#include +#include + +using namespace std; + +int main(){ + string str; + int counter_at = 0; + int counter_endl = 1; + while(1){ + cin >> str; + + for(auto i = str.begin()+1;i != str.end();i++){ + if((*(i-1) == 'a')&&(*i == 'a')){ + counter_at++; + } + } + if(*(str.end()-1) == '.'){ + break; + } + else{ + counter_endl++; + } + } + cout << counter_at << endl << counter_endl << endl; + + return 0; +} diff --git a/2016猜数字.cpp b/2016猜数字.cpp new file mode 100644 index 0000000..21dd8eb --- /dev/null +++ b/2016猜数字.cpp @@ -0,0 +1,31 @@ +#include +#include + +using namespace std; + +int main(){ + int max,target; + cin >> max >> target; + + int min = 1; + int guest = -1; + int counter = 0; + + while(1){ + counter++; + guest = (max - min + 1)/2 + min; + //cout << counter << " " << guest << " "<< max << "~" << min << endl; + + if(guest > target){ + max = guest; + } + else if(guest < target){ + min = guest; + } + else{ + break; + } + } + cout << counter; + return 0; +} diff --git a/2017成绩排名.cpp b/2017成绩排名.cpp new file mode 100644 index 0000000..e147de2 --- /dev/null +++ b/2017成绩排名.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n,temp; + vector array; + + set> score; + cin >> n; + + for(int i = 0;i < n;i++){ + cin >> temp; + score.insert(temp); + } + + cin >> n; + temp = 1; + for(auto i = score.begin();i != score.end();i++){ + if(*i != n){ + temp++; + } + else{ + cout << temp; + break; + } + } + + return 0; +} diff --git a/2017数塔路径.cpp b/2017数塔路径.cpp new file mode 100644 index 0000000..40eafeb --- /dev/null +++ b/2017数塔路径.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + + vector> tree(n); + + int temp; + for(int i = 0;i> temp; + tree[i].push_back(temp); + } + } + + vector> dp = tree; + + for(int i = n - 2;i >= 0;i--){ + for(int j = i;j >= 0;j--){ + dp[i][j] = max(dp[i + 1][j],dp[i + 1][j + 1]) + tree[i][j]; + } + } + + cout << dp[0][0]; + return 0; +} diff --git a/2017计算第几天.cpp b/2017计算第几天.cpp new file mode 100644 index 0000000..7b54efa --- /dev/null +++ b/2017计算第几天.cpp @@ -0,0 +1,42 @@ +#include + +using namespace std; + +int is_runnian(int y){ + return (y%4 == 0)&&(y%2000 != 0); +} + +int main(){ + int counter; + int y,m,d; + cin >> y >> m >> d; + + if(m <= 2){ + cout << (m - 1)*31 + d; + return 0; + } + else if(m <= 7){ + counter = 31 + 28 + is_runnian(y) + d; + for(int i = 3;i + +using namespace std; + +int is_sushu(int n){ + for(int i = 2;i*i> n; + + for(int i = 2;i<=n/2;i++){ + if(is_sushu(i)&&is_sushu(n-i)){ + cout << i << " " << n - i << endl; + } + } + + return 0; +} diff --git a/2018斐波那契数列.cpp b/2018斐波那契数列.cpp new file mode 100644 index 0000000..dda61be --- /dev/null +++ b/2018斐波那契数列.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + int a=0,b=1; + + if((n == 1)||(n == 0)){ + cout << n; + return 0; + } + + for(int i = 1;i +#include + +using namespace std; + +int sum(vector array,int start,int end){ + int num = 0; + for(int i = start;i <=end ;i++){ + num += array[i]; + } + return num; +} + +int main(){ + int n; + cin >> n; + + vector array(n); + + for(auto &i:array){ + cin >> i; + } + + int max = 0; + int start = 0; + int end = 0; + + for(int i = 0;i < n;i++){ + for (int j = 0;j < n - i;j++){ + if(max + +using namespace std; + +int main() { + int n; + cin >> n; + + for(int i = 1;i<=n;i++){ + if(i%2 != 0){ + for(int j=(i-1)*n+1;j<=i*n;j++){ + cout << j << " "; + } + } + else{ + for(int j=i*n;(i-1)*n+1<=j;j--){ + cout << j << " "; + } + } + cout << endl; + } + return 0; +} diff --git a/2019判断回文串.cpp b/2019判断回文串.cpp new file mode 100644 index 0000000..20ed496 --- /dev/null +++ b/2019判断回文串.cpp @@ -0,0 +1,26 @@ +#include +#include + + +using namespace std; + +int main(){ + string str; + cin >> str; + auto i = str.begin(); + auto j = str.end() - 1; + + while(i + +using namespace std; + +int func(int n){ + if(n == 1){ + return 0; + } + else if(n == 2){ + return 6; + } + else{ + return func(n - 1) + func(n - 2)*2; + } +} + +int main(){ + int n; + cin >> n; + cout << func(n); + + return 114514; +} diff --git a/2019递增子序列最大和.cpp b/2019递增子序列最大和.cpp new file mode 100644 index 0000000..3f5afc0 --- /dev/null +++ b/2019递增子序列最大和.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + vector array(n); + for(auto &i:array){ + cin >> i; + } + + int max_sum = -1; + + vector dp(n); + + dp[0] = array[0]; + + for(int i = 1;i < array.size();i++){ + dp[i] = array[i]; + for(int j = 0;j < i;j++){ + if(array[j] < array[i]){ + max_sum = max(dp[j],max_sum); + } + } + dp[i] += max_sum; + max_sum = -1; + } + + for(auto i:dp){ + max_sum = max(i,max_sum); + } + + cout << max_sum; + return 0; +} diff --git a/2019递归求阶乘.cpp b/2019递归求阶乘.cpp new file mode 100644 index 0000000..fe87706 --- /dev/null +++ b/2019递归求阶乘.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +int func(int n){ + if(n == 1){ + return n; + } + else{ + return n*func(n-1); + } +} + +int main(){ + int n; + cin >> n; + cout << func(n); +} diff --git a/2023成绩排名.cpp b/2023成绩排名.cpp new file mode 100644 index 0000000..ca8096e --- /dev/null +++ b/2023成绩排名.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +using namespace std; +vector a; + +int main() { + int n; + cin >> n; + + vector list(n); + + for (auto i = list.begin(); i != list.end(); i++) { + cin >> *i; + } + + unique(list.begin(),list.end()); + + sort(list.begin(), list.end(),[](int n1,int n2){ + return n1>n2; + }); + + cin >> n; + + cout << list[n - 1]; + + return 0; +} diff --git a/2023括号匹配.cpp b/2023括号匹配.cpp new file mode 100644 index 0000000..d0866d2 --- /dev/null +++ b/2023括号匹配.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +using namespace std; + +int main(){ + stack s; + string str; + cin >> str; + + for(auto i = str.begin();i != str.end();i++){ + switch(*i){ + case '(':s.push(')');break; + case '{':s.push('}');break; + case '[':s.push(']');break; + default: + if((*i == '}')||(*i == ']')||(*i == ')')){ + if(s.top() != *i){ + cout << "no" << endl; + return 1; + } + s.pop(); + } + } + } + cout << "yes" << endl; + return 0; +} diff --git a/2023斐波那契数.cpp b/2023斐波那契数.cpp new file mode 100644 index 0000000..9989f92 --- /dev/null +++ b/2023斐波那契数.cpp @@ -0,0 +1,24 @@ +#include +#include + +using namespace std; + +int fbnqs(int n1,int n2,int deepth){ + if(deepth == 1){ + return n1 + n2; + } + else{ + return fbnqs(n2,n1+n2,deepth -1); + } +} + +int main(){ + int n; + + cin >> n; + + cout << fbnqs(1,1,n - 2); + + return 0; +} + diff --git a/2023求个位数.cpp b/2023求个位数.cpp new file mode 100644 index 0000000..44796c2 --- /dev/null +++ b/2023求个位数.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +int main(){ + int n = 0; + cin >> n; + + int num = n; + + for(int i =0;i < n - 1;i++){ + num = num * n; + num = num%10; + } + cout << num; + return 0; +} + diff --git a/2024二元素数组.cpp b/2024二元素数组.cpp new file mode 100644 index 0000000..389f9cb --- /dev/null +++ b/2024二元素数组.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +bool is_sushu(int n){ + for(int i = 2;i*i<=n;i++){ + if(n%i == 0){ + return false; + } + } + return true; +} + +int main(){ + int n; + cin >> n; + + for(int i = 0;i < n/2;i++){ + if(is_sushu(i) && is_sushu(n - i)){ + cout << i <<" "<< n-i << endl; + } + } + + return 0; +} diff --git a/2024体重排序.cpp b/2024体重排序.cpp new file mode 100644 index 0000000..6579d93 --- /dev/null +++ b/2024体重排序.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +using namespace std; + +int main(){ + int n; + + pair person; + + cin >> n; + + vector > list; + + for(int i = 0;i < n;i++){ + cin >> person.first >> person.second; + list.push_back(person); + } + + sort(list.begin(),list.end(), + [](pair p1,pair p2){ + return (p1.second < p2.second); + }); + + for (const auto& p : list) { + cout << p.first << " "; + } + + + return 0; +} diff --git a/2024删除区间.cpp b/2024删除区间.cpp new file mode 100644 index 0000000..5001002 --- /dev/null +++ b/2024删除区间.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + + vector> array(n); + + for(auto &i:array){ + cin >> i.first >> i.second; + } + + sort(array.begin(),array.end(),[](pair a,pair b){ + return a.second < b.second; + }); + + int last_end = -114514; + int counter = 0; + + for(auto i:array){ + if(last_end < i.first){ + last_end = i.second; + } + else{ + counter++; + } + } + + cout << counter; + + return 0; +} diff --git a/2024逆序对的数量.cpp b/2024逆序对的数量.cpp new file mode 100644 index 0000000..be17105 --- /dev/null +++ b/2024逆序对的数量.cpp @@ -0,0 +1,28 @@ +#include +#include + +using namespace std; + +int main(){ + int n; + int count = 0; + cin >> n; + + vector list(n); + + for(int i = 0;i < n;i++){ + cin >> list[i]; + } + + for(int i = 0;i < n;i++){ + for(int j = i;j < n;j++){ + if(list[i]>list[j]){ + count++; + } + } + } + + cout << count; + + return 0; +}