添加函数

This commit is contained in:
zhuyijun 2021-08-09 00:38:53 +08:00
parent 98e8d6c74b
commit d0a39e6349
11 changed files with 289 additions and 1 deletions

View File

@ -19,4 +19,14 @@ foreach( appsourcefile ${APP_SOURCES} )
endforeach( appsourcefile ${APP_SOURCES} )
#add_executable(formore formore.cpp)
add_executable(outfile file/outfile.cpp)
add_executable(sumafile file/sumafile.cpp)
add_executable(sumafile file/sumafile.cpp)
add_executable(arrfun2 func/arrfun2.cpp)
add_executable(arrfun1 func/arrfun1.cpp)
add_executable(zzu_test zzu/test.cpp)
add_executable(vectorTest1 zzu/vector/vectorTest1.cpp)
add_executable(queueTest1 zzu/queue/queueTest1.cpp)
add_executable(queueTest2 zzu/queue/queueTest2.cpp)
add_executable(LG2278 zzu/queue/LG2278.cpp)
add_executable(queueTest3 zzu/queue/queueTest3.cpp)
add_executable(settest zzu/set/settest.cpp)
add_executable(stest1 dfs/stest1.cpp)

39
base/dfs/stest1.cpp Normal file
View File

@ -0,0 +1,39 @@
//
// Created by nicemoe on 2021/8/9.
//
#include <bits/stdc++.h>
using namespace std;
//0不用
int star[] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12};
int num = 0;
void Swap(int &, int &);
int Perm(int, int);
int main() {
Perm(1, 10);
cout << num << endl;
return 0;
}
int Perm(int begin, int end) {
int i;
if (begin == end) num++;
else {
for (i = begin; i <= end; i++) {
Swap(star[begin], star[i]);
Perm(begin + i, end);
Swap(star[begin], star[i]);
}
}
}
void Swap(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}

33
base/func/arrfun1.cpp Normal file
View File

@ -0,0 +1,33 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <iostream>
using namespace std;
const int ArSize = 8;
int sum_arr(int arr[], int n);
int main()
{
int cookies[ArSize]
{
1, 2, 3, 8, 16, 32, 64, 128
};
cout << &cookies << endl;
int sum = sum_arr(cookies, ArSize);
cout << "Total cookies eaten: " << sum;
return 0;
}
int sum_arr(int arr[], int n)
{
cout << &arr << endl;
int total = 0;
for (int i = 0; i < n; i++)
{
total += arr[i];
}
return total;
}

35
base/func/arrfun2.cpp Normal file
View File

@ -0,0 +1,35 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <iostream>
using namespace std;
const int ArSize = 8;
int sum_arr(const int arr[], int n);
int main()
{
int cookies[ArSize]
{
1, 2, 3, 8, 16, 32, 64, 128
};
cout << &cookies << endl;
int sum = sum_arr(cookies, ArSize);
cout << endl;
cout << "Total cookies eaten: " << sum;
return 0;
}
int sum_arr(const int *arr, int n)
{
int total = 0;
//打印arr数组地址
cout << &arr << endl;
for (int i = 0; i < n; i++)
{
total += arr[i];
}
return total;
}

24
base/zzu/queue/LG2278.cpp Normal file
View File

@ -0,0 +1,24 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
priority_queue<int,vector<int>,greater<> > pq;
int n,x,y;
cin >> n;
while(n--) {
cin >> x;
if(x==1){
cin >>y;
pq.push(y);
} else if (x==2){
cout << pq.top() << endl;
} else{
pq.pop();
}
}
return 0;
}

View File

@ -0,0 +1,35 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <bits/stdc++.h>
using namespace std;
int main()
{
queue<int> q;
q.push(1);
q.push(2);
cout << q.size() << endl;
cout << q.front() << endl;
q.pop();
cout << q.empty() << endl;
//默认优先先输出大的
priority_queue<int> pq;
//默认优先输出小的
// priority_queue<int,vector<int>,greater<int> > pq;
pq.push(1);
pq.push(150);
pq.push(100);
while (!pq.empty())
{
cout << pq.top() << endl;
pq.pop();
}
return 0;
}

View File

@ -0,0 +1,28 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <bits/stdc++.h>
using namespace std;
struct Node {
int x, y;
};
bool operator<(Node a, Node b) {
return a.x < b.x;
}
int main() {
priority_queue<Node> pq;
pq.push({1, 3});
pq.push({3, 2});
pq.push({2, 1});
while (!pq.empty()) {
cout << pq.top().x << ' ' << pq.top().y << endl;
pq.pop();
}
return 0;
}

View File

@ -0,0 +1,20 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> map;
map["name"] = 1;
map["sex"] = 2;
map["m"];
cout << map["name"] << endl;
cout << map["sex"] << endl;
cout << map["m"] << endl;
return 0;
}

12
base/zzu/set/settest.cpp Normal file
View File

@ -0,0 +1,12 @@
//
// Created by nicemoe on 2021/8/8.
//
m
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int main() {
bitset<N> b(5);
cout << b;
return 0;
}

20
base/zzu/test.cpp Normal file
View File

@ -0,0 +1,20 @@
//
// Created by nicemoe on 2021/8/8.
//
//万能头文件
#include <bits/stdc++.h>
using namespace std;
int main()
{
string n(3, '6'), s="a";
cout << n << " " << s;
string m = "嗯嗯";
// string m = *char();
// string n(int n,char c);
return 0;
}

View File

@ -0,0 +1,32 @@
//
// Created by nicemoe on 2021/8/8.
//
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
cout << v.back() << endl;
v.pop_back();
cout << v.back() << endl;
cout << v.front() << endl;
cout << v.size() << endl;//2
v.erase(v.begin());
cout << v.size() << endl;//1
v.resize(45);
cout << v.empty() << endl;
cout << v.size() << endl;//45
//下面两个以上相等 auto是自动推断根据后面的值的类型推断该变量的类型
vector<int>::iterator it = v.begin();
auto it1 = v.begin();
cout << *it1.operator+(0);
return 0;
}