Update Code

This commit is contained in:
Hmtsai 2024-04-21 13:45:54 +08:00
parent 495714749f
commit 2c8da23eb1
20 changed files with 450 additions and 68 deletions

BIN
src/a.out Executable file

Binary file not shown.

BIN
src/chunyou Executable file

Binary file not shown.

26
src/chunyou.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
int main() {
int N, M;
std::cin >> N >> M;
bool listn[N];
for (int i = 0; i < M; i++) {
int index;
std::cin >> index;
listn[index] = true;
}
bool flag = true;
for (int i = 0; i < N; i++) {
if (!listn[i]) {
flag = false;
std::cout << i << " ";
}
}
if (flag) {
std::cout << N;
}
return 0;
}

BIN
src/passwd_check Executable file

Binary file not shown.

68
src/passwd_check.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <iostream>
#include <vector>
int main() {
char last = 'A';
std::vector<std::string> passwds;
std::string user_input;
std::cin >> user_input;
{
// split
std::string passwd;
for (auto v : user_input) {
if (v == ',' || v == '\0') {
passwds.push_back(passwd);
passwd.clear();
}
passwd.push_back(v);
}
}
{
// check
for (int i = 0; i < passwds.size(); i++) {
if (passwds[i].size() > 12 || passwds[i].size() < 6) {
passwds.erase(passwds.begin() + i);
continue;
}
bool flag[3] = {false};
bool tflag = false;
bool fflag = false;
for (auto c : passwds[i]) {
if (c >= 'a' && c <= 'z') {
flag[0] = true;
} else if (c >= 'A' && c <= 'Z') {
flag[1] = true;
} else if (c >= '0' && c <= '9') {
flag[2] = true;
} else if (c == '!' || c == '@' || c == '#' || c == '$') {
tflag = true;
} else {
passwds.erase(passwds.begin() + i);
fflag = true;
break;
}
}
if (fflag) {
continue;
}
int count = 0;
for (auto v : flag) {
count += v;
}
if (count < 2 && !tflag) {
passwds.erase(passwds.begin() + i);
}
}
}
{
// output
for (auto passwd : passwds) {
std::cout << passwd << "\n";
}
}
return 0;
}

37
src/temp Normal file
View File

@ -0,0 +1,37 @@
X 0 1 2 3 4 5 6 7 8 9 10
0 1 1 1
1 1 1 1
2 1 1
3 1
4 1
5 1 1
6 1 1 1
7 1
8 1 1
9 1
10 1
visit[node:1]=1;
sum[node:1]=1;
maxw=0;
dfs(node:1){
for -> v=1{
if(!map[node:1][v:1]||visit[v:1]):true
{
continue;
}
}
for -> v=2{
if(!map[node:1][v:2]||visit[v:2]):true
{
continue;
}
}
for -> v=3{
if(!map[node:1][v:3]||visit[v:3]):false
dfs(node:v:3){
}
}
}

BIN
src/test Executable file

Binary file not shown.

2
src/test.cpp Normal file
View File

@ -0,0 +1,2 @@
#include<iostream>
int main(){std::string a("Hello World");std::cout<<a.size()<<" "<<a.length();return 0;}

BIN
src/tudeoulalu Executable file

Binary file not shown.

40
src/tudeoulalu.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstring>
#include <iostream>
const int maxn = 101;
int g[maxn][maxn], du[maxn], circuit[maxn], n, e, circuitpos, i, j, x, y, start;
void find_circuit(int i) {
int j;
for (int j = 1; i <= n; j++) {
if (g[i][j] == 1) {
g[j][i] = g[i][j] = 0;
find_circuit(j);
}
}
circuit[++circuitpos] = i;
}
int main() {
memset(g, 0, sizeof(g));
std::cin >> n >> e;
for (i = 1; i <= e; i++) {
std::cin >> x >> y;
g[y][x] = g[x][y] = 1;
du[x]++;
du[y]++;
}
start = 1;
for (i = 1; i <= n; i++) {
if (du[i] % 2 == 1) {
start = i;
}
}
circuitpos = 0;
find_circuit(start);
for (i = 1; i <= circuitpos; i++) {
std::cout << circuit[i] << ' ';
}
std::cout << "\n";
return 0;
}

View File

@ -1,104 +1,70 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
class Tdate class Tdate {
{ public:
public: Tdate(int setDay, int setMouth,
Tdate(int setDay, int setMouth, int setYear) // 构造函数没有返回类型,一个类可以由多个构造函数 int setYear) // 构造函数没有返回类型,一个类可以由多个构造函数
{ {
set(setDay, setMouth, setYear); set(setDay, setMouth, setYear);
} }
void set(int setDay, int setMouth, int setYear) void set(int setDay, int setMouth, int setYear) {
{
day = setDay; day = setDay;
mouth = setMouth; mouth = setMouth;
year = setYear; year = setYear;
} }
int isLeapYear() int isLeapYear() {
{
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
} }
void printYear() void printYear() { cout << year << "/" << mouth << "/" << day << endl; }
{ void nextDay() {
cout << year << "/" << mouth << "/" << day << endl; if (mouth == 2) {
} if (isLeapYear()) {
void nextDay() if (day + 1 > 29) {
{
if (mouth == 2)
{
if (isLeapYear())
{
if (day + 1 > 29)
{
mouth++; mouth++;
day = 1; day = 1;
} else {
day++;
} }
else } else {
{ if (day + 1 > 28) {
mouth++;
day = 1;
} else {
day++; day++;
} }
} }
else } else if (isBigMouth(mouth)) {
{ if (day + 1 > 31) {
if (day + 1 > 28)
{
mouth++; mouth++;
day = 1; day = 1;
} } else {
else
{
day++; day++;
} }
} } else if (mouth == 12) {
} if (day + 1 > 31) {
else if (isBigMouth(mouth))
{
if (day + 1 > 31)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
else if (mouth == 12)
{
if (day + 1 > 31)
{
year++; year++;
mouth = 1; mouth = 1;
day = 1; day = 1;
} } else {
else
{
day++; day++;
} }
} } else {
else if (day + 1 > 20) {
{
if (day + 1 > 20)
{
mouth++; mouth++;
day = 1; day = 1;
} } else {
else
{
day++; day++;
} }
} }
} }
private: private:
int day, mouth, year; int day, mouth, year;
int isBigMouth(int inMouth) int isBigMouth(int inMouth) {
{
int bigMouth[7] = {1, 3, 5, 7, 8, 10}; int bigMouth[7] = {1, 3, 5, 7, 8, 10};
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++) {
{ if (inMouth == bigMouth[i]) {
if (inMouth == bigMouth[i])
{
return 1; return 1;
} }
} }
@ -106,8 +72,7 @@ private:
} }
}; };
int main() int main() {
{
Tdate date(31, 12, 2011); Tdate date(31, 12, 2011);
date.printYear(); date.printYear();
date.nextDay(); date.nextDay();

View File

@ -0,0 +1,57 @@
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
template <typename T> int heap_put(T value, std::vector<T> &heap) {
heap.push_back(value);
if (heap.size() == 2) {
return heap.size() - 1;
}
int index = heap.size() - 1, parent;
while (index > 1) {
parent = index / 2;
if (heap[index] >= heap[parent]) {
break;
}
std::swap(heap[index], heap[parent]);
index = parent;
}
return index;
}
template <typename T> T heap_get(std::vector<T> &heap) {
T result = heap.front();
heap[1] = 0;
std::swap(heap[1], heap[heap.size() - 2]);
int it = 1;
while (it <= (heap.size() - 1 / 2)) {
int son_index = heap[it * 2] < heap[it * 2 + 1] ? it * 2 : it * 2 + 1;
if (heap[it] < heap[son_index]) {
break;
}
std::swap(heap[it], heap[son_index]);
it = son_index;
}
return result;
}
template <typename T>
void print_vector(std::vector<T> vector, char end = '\n') {
for (T value : vector) {
std::cout << value;
}
std::cout << end;
}
int main() {
std::vector<int> heap;
heap_put(4, heap);
print_vector(heap);
heap_put(1, heap);
print_vector(heap);
int tmp = heap_get(heap);
std::cout << tmp << std::endl;
print_vector(heap);
return 0;
}

View File

@ -0,0 +1,48 @@
#include <iostream>
#include <utility>
int heap[10001], heap_size = 0;
void put(int d) {
int son, pa;
heap[++heap_size] = d;
son = heap_size;
while (son > 1) {
pa = son >> 1;
if (heap[son] >= heap[pa]) {
break;
}
std::swap(heap[son], heap[pa]);
son = pa;
}
}
int get() {
int pa, son, res;
res = heap[1];
heap[1] = heap[heap_size--];
pa = 1;
while (pa * 2 <= heap_size) {
son = pa * 2;
if (son < heap_size && heap[son + 1] < heap[son])
son++;
if (heap[pa] <= heap[son])
break;
pa = son;
}
return res;
}
int main() {
int fruit_num;
std::cin >> fruit_num;
int fruit_nums[fruit_num + 1];
for (auto &value : fruit_nums) {
std::cin >> value;
put(value);
}
int ans = 0;
for (int i = 0; i < fruit_num; i++) {
int x = get();
int y = get();
ans += x + y;
put(x + y);
}
std::cout << ans << std::endl;
}

BIN
src/type/heap/heap_sort Executable file

Binary file not shown.

View File

@ -0,0 +1,42 @@
#include <iostream>
void heap(int r[], int nn, int ii) {
int x, i = ii, j;
x = r[ii];
j = 2 * i;
while (j <= nn) {
if (j < nn && r[j] < r[j + 1]) {
j++;
}
if (x < r[j]) {
r[i] = r[j];
i = j;
j = 2 * i;
} else {
j = nn + 1;
}
}
r[i] = x;
}
int a[100001];
int i, temp, n;
int main() {
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
for (int i = n / 2; i >= 1; i--) {
heap(a, n, i);
}
for (int i = n; i >= 2; i--) {
std::swap(a[1], a[i]);
heap(a, i - 1, 1);
}
for (int i = 1; i <= n; i++) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
return 0;
}

BIN
src/type/heap/merge_fruits Executable file

Binary file not shown.

View File

@ -0,0 +1,28 @@
#include <iostream>
#include <queue>
int n;
std::priority_queue<int, std::vector<int>, std::greater<int>> h;
void () {
int , , , ans = 0;
std::cin >> n;
for ( = 1; <= n; ++) {
std::cin >> ;
h.push();
}
for ( = 1; < n; ++) {
= h.top();
h.pop();
= h.top();
h.pop();
ans += + ;
h.push( + );
}
std::cout << ans << std::endl;
}
int main() {
();
return 0;
}

View File

@ -0,0 +1,36 @@
#include <iostream>
struct node{
node *left, *right, *parent;
char data;
};
void makeTree(std::string X, std::string Z){
if(X.size()==0){
return ;
}
char root = X[0];
unsigned long index = Z.find(root);
std::string nextX,nextZ;
for(int i=0;i<index;i++){
nextX.push_back(X[1+i]);
nextZ.push_back(X[i]);
}
makeTree(nextX, nextZ);
nextX.clear();
nextZ.clear();
for(int i=index;i<X.size();i++){
nextX.push_back(X[1+i]);
nextZ.push_back(X[i]);
}
makeTree(nextX, nextZ);
std::cout<<root;
}
int main(){
std::string X,Z;
std::cin>>X>>Z;
return 0;
}

View File

@ -0,0 +1,34 @@
// Copyright 2077 Hmtsai
#include <iostream>
std::string Z, C;
int len, flag[1005];
void xianxv(int l, int r) {
if (l > r) {
return;
}
int u, min = 0x3f3f3f3f;
for (int k = 1; k <= r; k++) {
if (flag[Z[k] - 'A' + 1] < min) {
min = flag[Z[k] - 'A' + 1];
u = k;
}
}
std::cout << a[u];
if (u > 1)
dg(1, u - 1);
if (u < r)
dg(u + 1, r);
}
int main() {
std::cin >> Z >> C;
len = b.size();
for (int i = 0; i < len; i++) {
flag = [b[i] - 'A' + 1] = i;
}
dg(0, a.size() - 1);
return 0;
}

View File

@ -1,5 +1,4 @@
#include "iostream" #include "iostream"
#include <map>
#include <vector> #include <vector>
int main() { int main() {