code
stringlengths 1
1.05M
| repo_name
stringlengths 6
83
| path
stringlengths 3
242
| language
stringclasses 222
values | license
stringclasses 20
values | size
int64 1
1.05M
|
|---|---|---|---|---|---|
#include <stdio.h>
int main(int argc, char const *argv[])
{
printf("Hello World!\n");
return 0;
}
|
2301_76233439/shujujiegou
|
src/main.c
|
C
|
unknown
| 108
|
/*
* Copyright (c) 2025 chicken8225
* All rights reserved.
*
* This file/program is protected by copyright law and international treaties.
* Unauthorized reproduction or distribution of this file/program, or any portion
* of it, may result in severe civil and criminal penalties.
*
* Date: 2025-07-21
*/
#include "infInt.h"
infInt::infInt() : num("0") {}
infInt::infInt(const infInt& other) : num(other.num) {}
infInt::infInt(infInt&& other) noexcept : num(std::move(other.num)) {}
infInt::infInt(const std::string& s) : num(s) { delZero(); }
infInt::infInt(int x) : num(std::to_string(x)) { delZero(); }
infInt& infInt::operator=(const infInt& other) {
if (this != &other) {
num = other.num;
delZero();
}
return *this;
}
infInt& infInt::operator=(infInt&& other) noexcept {
if (this != &other) num = std::move(other.num);
return *this;
}
infInt& infInt::operator=(const std::string& s) {
num = s;
delZero();
return *this;
}
infInt& infInt::operator=(const int& x) {
num = std::to_string(x);
delZero();
return *this;
}
std::string infInt::copy() const {
return num;
}
bool infInt::operator<(const infInt& other) const {
if (num.size() != other.num.size()) return num.size() < other.num.size();
return num < other.num;
}
bool infInt::operator<(const std::string& s) const {
return *this < infInt(s);
}
bool infInt::operator<(const int& n) const {
return *this < infInt(n);
}
bool infInt::operator==(const infInt& other) const {
return num == other.num;
}
bool infInt::operator==(const std::string& s) const {
return num == s;
}
bool infInt::operator==(const int& n) const {
return *this == infInt(n);
}
bool infInt::operator>(const infInt& other) const {
if (num.size() != other.num.size()) return num.size() > other.num.size();
return num > other.num;
}
bool infInt::operator>(const std::string& s) const {
return *this > infInt(s);
}
bool infInt::operator>(const int& n) const {
return *this > infInt(n);
}
bool infInt::operator<=(const infInt& other) const {
return *this < other || *this == other;
}
bool infInt::operator<=(const std::string& s) const {
return *this <= infInt(s);
}
bool infInt::operator<=(const int& n) const {
return *this <= infInt(n);
}
bool infInt::operator!=(const infInt& other) const {
return !(*this == other);
}
bool infInt::operator!=(const std::string& s) const {
return *this != infInt(s);
}
bool infInt::operator!=(const int& n) const {
return *this != infInt(n);
}
bool infInt::operator>=(const infInt& other) const {
return *this > other || *this == other;
}
bool infInt::operator>=(const std::string& s) const {
return *this >= infInt(s);
}
bool infInt::operator>=(const int& n) const {
return *this >= infInt(n);
}
infInt infInt::operator+(const infInt& other) const {
std::string a = num, b = other.num;
std::reverse(a.begin(), a.end());
std::reverse(b.begin(), b.end());
if (a.size() < b.size()) std::swap(a, b);
int len1 = a.size(), len2 = b.size(), carry = 0;
std::string ans = "";
for(int i = 0; i < len1; i++) {
int res = a[i] - '0' + carry;
if (len2 > i) res += b[i] - '0';
carry = res / 10;
res %= 10;
ans += res + '0';
}
if (carry > 0) ans += carry + '0';
std::reverse(ans.begin(), ans.end());
return infInt(ans);
}
infInt infInt::operator-(const infInt& other) const {
std::string a = num, b = other.num;
if (a < b) {
throw std::domain_error("This type does not support negative numbers.");
}
std::reverse(a.begin(), a.end());
std::reverse(b.begin(), b.end());
int len1 = a.size(), len2 = b.size(), carry = 0;
std::string tmp = "";
for(int i = 0; i < len1; i++) {
int res = a[i] - '0' - carry;
if (len2 > i) res -= b[i] - '0';
carry = res < 0;
res = (res + 10) % 10;
tmp += res + '0';
}
std::reverse(tmp.begin(), tmp.end());
return infInt(tmp);
}
infInt infInt::operator*(const infInt& other) const {
if (isZero() || other.isZero()) return infInt("0");
if (*this == infInt("1")) return other;
if (other == infInt("1")) return *this;
if (num.size() <= KARATSUBA_THRESHOLD && other.num.size() <= KARATSUBA_THRESHOLD) {
int a = stoi(num), b = stoi(other.num);
return infInt(a * b);
}
size_t m = std::max(num.size(), other.num.size()) / 2;
infInt high1(num.substr(0, num.size() - m));
infInt low1(num.substr(num.size() - m));
infInt high2(other.num.substr(0, other.num.size() - m));
infInt low2(other.num.substr(other.num.size() - m));
infInt z0 = low1 * low2;
infInt z1 = (low1 + high1) * (low2 + high2);
infInt z2 = high1 * high2;
infInt part1 = z2;
for (size_t i = 0; i < 2 * m; i++) part1.num += "0";
infInt part2 = z1 - z2 - z0;
for (size_t i = 0; i < m; i++) part2.num += "0";
return part1 + part2 + z0;
}
infInt infInt::operator/(const infInt& other) const {
if (other.isZero()) throw std::domain_error("The divisor cannot be zero.");
if (*this < other) return infInt(0);
if (*this == other) return infInt(1);
infInt a = *this, c = 0, d = 0;
for(auto ch : num) {
d = d * infInt(10) + infInt(ch - '0');
int digit = 0;
while (d >= other) {
d -= other;
digit++;
}
c.num += std::to_string(digit);
}
c.delZero();
return c;
}
infInt infInt::operator%(infInt other) const {
if (other.isZero()) throw std::domain_error("The divisor cannot be zero.");
if (other.num == "1") return infInt("0");
if (*this < other) return *this;
return *this - *this / other * other;
}
infInt infInt::operator^(const infInt& other) const {
return this->pow(other);
}
infInt& infInt::operator+=(const infInt& other) {
*this = *this + other;
return *this;
}
infInt& infInt::operator-=(const infInt& other) {
*this = *this - other;
return *this;
}
infInt& infInt::operator*=(const infInt& other) {
*this = *this * other;
return *this;
}
infInt& infInt::operator/=(const infInt& other) {
*this = *this / other;
return *this;
}
infInt& infInt::operator%=(const infInt& other) {
*this = *this % other;
return *this;
}
infInt& infInt::operator^=(const infInt& other) {
*this = this->pow(other);
return *this;
}
infInt& infInt::operator++() {
*this = *this + infInt("1");
return *this;
}
infInt infInt::operator++(int) {
infInt old = *this;
++(*this);
return old;
}
infInt& infInt::operator--() {
*this = *this - infInt("1");
return *this;
}
infInt infInt::operator--(int) {
infInt old = *this;
--(*this);
return old;
}
infInt infInt::pow(const infInt& other) const {
if (other.isZero()) return infInt(1);
infInt ans = 1, base = *this, exp = other;
while (exp > 0) {
if (exp % 2 == 1) ans *= base;
base *= base;
exp /= 2;
}
return ans;
}
|
2301_76283474/infInt
|
infInt.cpp
|
C++
|
unknown
| 7,331
|
/*
* Copyright (c) 2025 chicken8225
* All rights reserved.
*
* This file/program is protected by copyright law and international treaties.
* Unauthorized reproduction or distribution of this file/program, or any portion
* of it, may result in severe civil and criminal penalties.
*
* Date: 2025-07-21
*/
#ifndef INFINT_H
#define INFINT_H
#include <algorithm>
#include <cctype>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
class infInt {
private:
static constexpr size_t KARATSUBA_THRESHOLD = 4;
std::string num;
void delZero();
bool isZero() const;
infInt pow(const infInt& other) const;
public:
infInt();
infInt(const infInt& other);
infInt(infInt&& other) noexcept;
infInt(const std::string& s);
infInt(int x);
int to_int() const {
return std::stoi(num);
}
long to_long() const {
return std::stol(num);
}
operator int() const {
return std::stoi(num);
}
operator long() const {
return std::stol(num);
}
infInt& operator=(const infInt& other);
infInt& operator=(infInt&& other) noexcept;
infInt& operator=(const std::string& s);
infInt& operator=(const int& x);
friend std::ostream& operator<<(std::ostream& os, const infInt& n) {
os << n.num;
return os;
}
friend std::istream& operator>>(std::istream& is, infInt& n) {
is >> n.num;
for(char c : n.num) {
if (!std::isdigit(c)) {
throw std::invalid_argument("The input must contain only digits (0-9).");
}
}
n.delZero();
return is;
}
std::string copy() const;
bool operator<(const infInt& other) const;
bool operator<(const std::string& s) const;
bool operator<(const int& n) const;
bool operator==(const infInt& other) const;
bool operator==(const std::string& s) const;
bool operator==(const int& n) const;
bool operator>(const infInt& other) const;
bool operator>(const std::string& s) const;
bool operator>(const int& n) const;
bool operator<=(const infInt& other) const;
bool operator<=(const std::string& s) const;
bool operator<=(const int& n) const;
bool operator!=(const infInt& other) const;
bool operator!=(const std::string& s) const;
bool operator!=(const int& n) const;
bool operator>=(const infInt& other) const;
bool operator>=(const std::string& s) const;
bool operator>=(const int& n) const;
infInt operator+(const infInt& other) const;
infInt operator-(const infInt& other) const;
infInt operator*(const infInt& other) const;
infInt operator/(const infInt& other) const;
infInt operator%(const infInt& other) const;
infInt operator^(const infInt& other) const;
infInt& operator+=(const infInt& other);
infInt& operator-=(const infInt& other);
infInt& operator*=(const infInt& other);
infInt& operator/=(const infInt& other);
infInt& operator%=(const infInt& other);
infInt& operator^=(const infInt& other);
infInt& operator++();
infInt operator++(int);
infInt& operator--();
infInt operator--(int);
};
#endif
|
2301_76283474/infInt
|
infInt.h
|
C++
|
unknown
| 3,358
|
#include <iostream>
#include "infInt.h"
using namespace std;
int main() {
infInt a, b;
cin >> a >> b;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a / b = " << a / b << endl;
cout << "b / a = " << b / a << endl;
cout << "a % b = " << a % b << endl;
cout << "b % a = " << b % a << endl;
if (a > b) cout << "a > b" << endl;
else if (a < b) cout << "a < b" << endl;
else cout << "a = b" << endl;
cout << "end" << endl;
return 0;
}
|
2301_76283474/infInt
|
main.cpp
|
C++
|
unknown
| 590
|
#include <iostream>
#include "gobang.h"
using namespace std;
int main(int argc, char const *argv[])
{
char chess_board[ROW][COL] = {'\0'};
gobang_ui_init(chess_board);
show_chess_board(chess_board);
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋模板/01-棋盘初始化和展示函数.cpp
|
C++
|
unknown
| 238
|
#include <iostream>
#include "gobang.h"
using namespace std;
int main(int argc, char const *argv[])
{
/**
* flag 是一个游戏胜利判断条件
*/
int flag = 0;
/**
* 记录当前落子的总个数,同时可以利用 % 2 判断
* 落子的玩家是哪一个玩家
*/
int count = 0;
int row_index = 0;
int col_index = 0;
char player = '\0';
char chess_board[ROW][COL] = {'\0'};
gobang_ui_init(chess_board);
while (1)
{
show_chess_board(chess_board);
if (count % 2 == 0)
{
cout << "执黑落子";
player = BLACK;
}
else
{
cout << "执白落子";
player = WHITE;
}
cout << ",请输入对应的下标位置, 例如 : 2 3 : ";
cin >> row_index >> col_index;
count += place_stone(chess_board, row_index, col_index, player);
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋模板/02-落子实现.cpp
|
C++
|
unknown
| 957
|
#include <iostream>
#include "gobang.h"
using namespace std;
int main(int argc, char const *argv[])
{
int ret = 0;
/**
* flag 是一个游戏胜利判断条件
*/
int flag = 0;
/**
* 记录当前落子的总个数,同时可以利用 % 2 判断
* 落子的玩家是哪一个玩家
*/
int count = 0;
int row_index = 0;
int col_index = 0;
char player = '\0';
char chess_board[ROW][COL] = {'\0'};
gobang_ui_init(chess_board);
while (1)
{
show_chess_board(chess_board);
if (count % 2 == 0)
{
cout << "执黑落子";
player = BLACK;
}
else
{
cout << "执白落子";
player = WHITE;
}
cout << ",请输入对应的下标位置, 例如 : 2 3 : ";
cin >> row_index >> col_index;
ret = place_stone(chess_board, row_index, col_index, player);
if (ret)
{
flag = is_win(chess_board, row_index, col_index, player);
cout << "flag = " << flag << endl;
}
count += ret;
if (flag)
{
cout << (player == BLACK ? "执黑获胜" : "执白获胜") << endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋模板/03-获胜判断.cpp
|
C++
|
unknown
| 1,287
|
#include "gobang.h"
using namespace std;
void gobang_ui_init(char chess_board[][COL])
{
memset(chess_board, '+', ROW * COL);
}
void show_chess_board(char chess_board[][COL])
{
cout << " 1 2 3 4 5 6 7 8 9 A B C D E F" << endl;
for (int i = 0; i < ROW; i++)
{
if (i + 1 < 10)
{
cout << i + 1;
}
else
{
cout << (char)('A' + i - 9);
}
for (int j = 0; j < COL; j++)
{
cout << ' ' << chess_board[i][j];
}
cout << endl;
}
}
int place_stone(char chess_board[][COL], int row_index, int col_index, char player)
{
row_index -= 1;
col_index -= 1;
if (row_index < 0 || row_index > ROW - 1 || col_index < 0 || col_index > COL - 1 || chess_board[row_index][col_index] != '+')
{
cout << "您落子的下标位置不符合游戏规则" << endl;
return 0;
}
chess_board[row_index][col_index] = player;
return 1;
}
int is_win(char chess_board[][COL], int row_index, int col_index, char player)
{
row_index -= 1;
col_index -= 1;
/*
横向判断
row_index 不变
col_index 在不超过合理下标范围以内的情况下,-4 作为左侧限制,+4 作为右侧限制
*/
/*
count 记录当前玩家对应棋子的连续总个数。
*/
int count = 0;
for (int j = (col_index - 4 > 0 ? col_index - 4 : 0);
j <= (col_index + 4 > COL - 1 ? COL - 1 : col_index + 4);
j++)
{
if (chess_board[row_index][j] == player)
{
count += 1;
if (5 == count)
{
return 1;
}
}
else
{
count = 0;
}
}
count = 0;
/*
纵向判断
col_index 不变
row_index 在不超过合理下标范围以内的情况下,-4 作为顶部限制,+4 作为底部限制
*/
for (int i = (row_index - 4 > 0 ? row_index - 4 : 0);
i <= (row_index + 4 > ROW - 1 ? ROW - 1 : row_index + 4);
i++)
{
if (chess_board[i][col_index] == player)
{
count += 1;
if (5 == count)
{
return 1;
}
}
else
{
count = 0;
}
}
/*
\ 正对角方向
需要明确
1. 左上角起始下标位置
2. 右下角终止下标位置
3. row_index 和 col_index 下标都是递增关系。
*/
// 左上角起始下标位置
int left_row_dist = row_index - 4 > 0 ? 4 : row_index - 0;
int left_col_dist = col_index - 4 > 0 ? 4 : col_index - 0;
int left_min_dist = left_row_dist > left_col_dist ? left_col_dist : left_row_dist;
/*
左侧起始下标位置是
[row_index - left_min_dist][col_index - left_min_dist]
*/
// 右下角终止下标位置
int right_row_dist = row_index + 4 > ROW - 1 ? ROW - 1 - row_index : 4;
int right_col_dist = col_index + 4 > COL - 1 ? COL - 1 - col_index : 4;
int right_min_dist = right_row_dist > right_col_dist ? right_col_dist : right_row_dist;
/*
右侧终止下标位置是
[row_index + right_min_dist][col_index + right_min_dist]
*/
count = 0;
for (int i = row_index - left_min_dist, j = col_index - left_min_dist;
i <= row_index + right_min_dist && j <= col_index + right_min_dist;
i++, j++)
{
if (chess_board[i][j] == player)
{
count += 1;
if (5 == count)
{
return 1;
}
}
else
{
count = 0;
}
}
/*
/ 反对角方向
需要明确
1. 左下角起始下标位置
row_index + 4 判断
col_index - 4 判断
2. 右上角终止下标位置
row_index - 4 判断
col_index + 4 判断
3. row_index 行下标递减关系,col_index 列下标递增关系
*/
left_row_dist = row_index + 4 > ROW - 1 ? ROW - 1 - row_index : 4;
left_col_dist = col_index - 4 > 0 ? 4 : col_index - 0;
left_min_dist = left_row_dist > left_col_dist ? left_col_dist : left_row_dist;
/*
左下角起始下标位置
[row_index + left_nmin_dist][col_index - left_min_dist];
*/
right_row_dist = row_index - 4 > 0 ? 4 : row_index - 0;
right_col_dist = col_index + 4 > COL - 1 ? COL - 1 - row_index : 4;
right_min_dist = right_row_dist > right_col_dist ? right_col_dist : right_row_dist;
/*
右上角终止下标位置
[row_index - right_min_dist][col_index + right_min_dist];
*/
for (int i = row_index + left_min_dist, j = col_index - left_min_dist;
i >= row_index - right_min_dist, j <= col_index + right_min_dist;
i--, j++)
{
if (chess_board[i][j] == player)
{
count += 1;
if (5 == count)
{
return 1;
}
}
else
{
count = 0;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋模板/gobang.cpp
|
C++
|
unknown
| 5,120
|
#ifndef _GO_BANG_
#define _GO_BANG_
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define ROW 15
#define COL 15
#define BLACK 'B'
#define WHITE 'O'
/**
* 棋盘初始化函数,提供当前函数的参数是个 char 类型二维数组,
* 数组的一维下标和二维下标由 ROW 和 COL 两个宏常量控制
*
* @param chess_board 用户提供的 char 类型二维数组
*/
void gobang_ui_init(char chess_board[][COL]);
/**
* 棋盘展示函数,,提供当前函数的参数是个 char 类型二维数组,
* 数组的一维下标和二维下标由 ROW 和 COL 两个宏常量控制
*
* @param chess_board 用户提供的 char 类型二维数组
*/
void show_chess_board(char chess_board[][COL]);
/**
* 落子函数,根据当前玩家提供的行列下标位置,落子对应玩家的棋子
*
* @param chess_board 当前五子棋对应的棋盘 char 类型二维数组
* @param row_index 用户指定落子的行下标位置
* @param col_index 用户指定落子的列下标位置
* @param player 对应用户,利用 BLACK 和 WHITE 两个宏区分用户玩家
* @return 落子成功返回 1,否则返回 0
*/
int place_stone(char chess_board[][COL], int row_index, int col_index, char player);
/**
* 判断是否游戏获胜条件
*
* @param chess_board 当前五子棋对应的棋盘 char 类型二维数组
* @param row_index 用户指定落子的行下标位置
* @param col_index 用户指定落子的列下标位置
* @param player 对应用户,利用 BLACK 和 WHITE 两个宏区分用户玩家
* @return 游戏胜利返回 1,否则返回 0
*/
int is_win(char chess_board[][COL], int row_index, int col_index, char player);
#endif
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋模板/gobang.h
|
C++
|
unknown
| 1,744
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
// #define ROW 10
// #define COL 10
// // 打印用户界面
// void print_the_board(char chessboard[][COL])
// {
// for (int i = 0; i < ROW; i++)
// {
// for (int j = 0; j < COL; j++)
// {
// cout << chessboard[i][j] << " ";;
// }
// cout << endl;
// }
// }
// //初始化棋盘
// void initialise_the_boar(char chessboard[][COL])
// {
// for (int i = 0; i < ROW; i++)
// {
// for (int j = 0; j < COL; j++)
// {
// chessboard[i][j] = '0';
// }
// }
// }
// void enter_coordinates(char chessboard[][COL], int number)
// {
// int a = 0;
// int b = 0;
// cout << "请输入落子位置" << endl;
// cin >> a >> b;
// if(a < 0 || a >= ROW || b < 0 || b >= COL)
// {
// cout << "位置违规,请重新输入" << endl;
// }
// }
int main(int argc, char const* argv[])
{
// int number = 1;
// char chessboard [ROW][COL] = {'0'};
// //初始化棋盘
// initialise_the_boar(chessboard);
// // 打印用户界面
// print_the_board(chessboard);
// //用户输入坐标
// enter_coordinates(chessboard, number);
string str = "ab cd"
for (int i = 0; i < 4; i++)
{
cout << str[i] << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋练习/01_五子棋.cpp
|
C++
|
unknown
| 1,416
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
#define ROW 15
#define COL 15
// 打印用户界面
void print_the_board(char chessboard[][COL])
{
// 打印列号
cout << " ";
for (int i = 0; i < COL; i++)
{
cout << hex << i << " ";
}
cout << endl;
for (int i = 0; i < ROW; i++)
{
// 打印行号
cout << hex << i << " ";
for (int j = 0; j < COL; j++)
{
if (chessboard[i][j] == '0')
{
cout << ". ";
}
else
{
cout << chessboard[i][j] << " ";
}
}
cout << endl;
}
}
// 初始化棋盘
void initialise_the_board(char chessboard[][COL])
{
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
chessboard[i][j] = '0';
}
}
}
// 用户输入坐标
void enter_coordinates(char chessboard[][COL], int &number)
{
int a = 0;
int b = 0;
int valid = false;
while (!valid)
{
cout << "玩家 " << (number % 2 == 1? "黑子玩家" : "白子玩家")
<< " 请输入落子位置(行 列): " << endl;
cin >> a >> b;
if (a >= 0 && a < ROW && b >= 0 && b < COL
&& chessboard[a][b] == '0')
{
valid = true;
chessboard[a][b] = (number % 2 == 1)? 'B' : 'W';
}
else
{
cout << "位置违规或已被占用,请重新输入" << endl;
}
}
number++;
}
// 检查是否获胜
bool check_win(char chessboard[][COL])
{
// 检查行
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j <= COL - 5; j++)
{
if (chessboard[i][j] != '0' &&
chessboard[i][j] == chessboard[i][j + 1] &&
chessboard[i][j] == chessboard[i][j + 2] &&
chessboard[i][j] == chessboard[i][j + 3] &&
chessboard[i][j] == chessboard[i][j + 4])
{
return true;
}
}
}
// 检查列
for (int j = 0; j < COL; j++)
{
for (int i = 0; i <= ROW - 5; i++)
{
if (chessboard[i][j]!= '0' &&
chessboard[i][j] == chessboard[i + 1][j] &&
chessboard[i][j] == chessboard[i + 2][j] &&
chessboard[i][j] == chessboard[i + 3][j] &&
chessboard[i][j] == chessboard[i + 4][j] )
{
return true;
}
}
}
// 检查主对角线
for (int i = 0; i <= ROW - 5; i++)
{
for (int j = 0; j <= COL - 5; j++)
{
if (chessboard[i][j]!= '0' &&
chessboard[i][j] == chessboard[i + 1][j + 1] &&
chessboard[i][j] == chessboard[i + 2][j + 2] &&
chessboard[i][j] == chessboard[i + 3][j + 3] &&
chessboard[i][j] == chessboard[i + 4][j + 4])
{
return true;
}
}
}
// 检查副对角线
for (int i = 0; i <= ROW - 5; i++)
{
for (int j = 4; j < COL; j++)
{
if (chessboard[i][j]!= '0' &&
chessboard[i][j] == chessboard[i + 1][j - 1] &&
chessboard[i][j] == chessboard[i + 2][j - 2] &&
chessboard[i][j] == chessboard[i + 3][j - 3] &&
chessboard[i][j] == chessboard[i + 4][j - 4])
{
return true;
}
}
}
return false;
}
// 检查棋盘是否已满
bool is_board_full(char chessboard[][COL])
{
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
if (chessboard[i][j] == '0')
{
return false;
}
}
}
return true;
}
{
int number = 1;
char chessboard [ROW][COL] = {'0'};
// 初始化棋盘
initialise_the_board(chessboard);
// 打印用户界面
print_the_board(chessboard);
while (true)
{
//用户输入坐标
enter_coordinates(chessboard, number);
// 打印用户界面
print_the_board(chessboard);
if (check_win(chessboard))
{
cout << "玩家 " << ((number - 1) % 2 == 1? "X" : "O")
<< " 获胜!" << endl;
break;
}
if (is_board_full(chessboard))
{
cout << "平局!" << endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋练习/02_ 五子棋.cpp
|
C++
|
unknown
| 4,898
|
// 检查是否获胜
bool check_win(char chessboard[][COL])
{
// 检查行
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j <= COL - 5; j++)
{
if (chessboard[i][j] != '0' &&
chessboard[i][j] == chessboard[i][j + 1] &&
chessboard[i][j] == chessboard[i][j + 2] &&
chessboard[i][j] == chessboard[i][j + 3] &&
chessboard[i][j] == chessboard[i][j + 4])
{
return true;
}
}
}
// 检查列
for (int j = 0; j < COL; j++)
{
for (int i = 0; i <= ROW - 5; i++)
{
if (chessboard[i][j] != '0' &&
chessboard[i][j] == chessboard[i + 1][j] &&
chessboard[i][j] == chessboard[i + 2][j] &&
chessboard[i][j] == chessboard[i + 3][j] &&
chessboard[i][j] == chessboard[i + 4][j] )
{
return true;
}
}
}
// 检查主对角线
for (int i = 0; i <= ROW - 5; i++)
{
for (int j = 0; j <= COL - 5; j++)
{
if (chessboard[i][j] != '0' &&
chessboard[i][j] == chessboard[i + 1][j + 1] &&
chessboard[i][j] == chessboard[i + 2][j + 2] &&
chessboard[i][j] == chessboard[i + 3][j + 3] &&
chessboard[i][j] == chessboard[i + 4][j + 4])
{
return true;
}
}
}
// 检查副对角线
for (int i = 0; i <= ROW - 5; i++)
{
for (int j = 4; j < COL; j++)
{
if (chessboard[i][j] != '0' &&
chessboard[i][j] == chessboard[i + 1][j - 1] &&
chessboard[i][j] == chessboard[i + 2][j - 2] &&
chessboard[i][j] == chessboard[i + 3][j - 3] &&
chessboard[i][j] == chessboard[i + 4][j - 4])
{
return true;
}
}
}
return false;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋练习/03_shifouhuosdheng1.cpp
|
C++
|
unknown
| 1,995
|
#include <iostream>
#include "bobang.h"
using namespace std;
int main(int argc, char const *argv[])
{
int ret = 0;
/**
* flag 是一个游戏胜利判断条件
*/
int flag = 0;
/**
* 记录当前落子的总个数,同时可以利用 % 2 判断
* 落子的玩家是哪一个玩家
*/
int count = 0;
int row_index = 0;
int col_index = 0;
int player = '\0';
char chess_board[ROW][COL] = {'\0'};
gobang_ui_init(chess_board);
while (1)
{
show_chess_board(chess_board);
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋练习/04_获胜判断.cpp
|
C++
|
unknown
| 583
|
#ifndef _GO_BANG_
#define _GO_BANG_
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define ROW 15
#define COL 15
#define BACK 'B'
#define WHITE '0'
/**
* 期盼初始化函数,提供当前函数的参数是个 char 类型二维数组,
* 数组的一维下标和二维下标由 ROW 和 COL 两个宏常量控制
*
* @param chess_board 用户提供的 char 类型二维数组
*/
void gobang_ui_init(char chess_board[][COL]);
/**
* 期盼展示函数,提供当前函数的参数是个 char 类型二维数组
* 数组的一维下标和二位小标由 ROW 和 COL 两个宏常量控制
*
* @param chess_board 用户提供的 char 了类型二维数组
*/
void show_chess_board(char chess_board[][COL]);
/**
* 落子函数,根据当前玩家提供的行列下标位置,骡子对应玩家的妻子
*
* @param chess_board 当前五子棋对应的棋盘 char 类型二维数组
* @param row_index 用户指定落子的行下标位置
* @param c0l_index 用户指定罗自动列下标位置
* @param player 对应用户,利用 BLACK 和 WITE 两个宏区分用户玩家
* @return 落子成功返回 1 ,否则返回 0,。
*/
int place_stone(char chess_board[][COL], int row_index, int col_index, char player);
/**
* 判断是否游戏获胜条件
*
* @param chess_board 当前五子棋对应棋的棋盘 char 类型数组
* @param row_index 用户指定落子的行下标位置
* @param col_index 用户指定落子的列下标位置
* @param player 对应用户,利用 BLACK 和 WHITE 两个宏区分用户玩家
* @return 游戏胜利返回 1 , 否则返回 0
*/
int is_win(char chess_board[][COL], int row_index, char player);
#endif
|
2201_76097352/learning-records
|
ac1/五子棋/五子棋练习/gobang.h
|
C++
|
unknown
| 1,744
|
#include "game.h"
using namespace std;
void gobang_ui_init(char gobang_ui[][COL])
{
memset(gobang_ui, ' ', ROW * COL);
return;
}
void show_gobong_ui(char gobang_ui[][COL])
{
cout << " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14" << endl;
for (int i = 0; i < ROW; i++)
{
if (i <= 9)
{
cout << ' ' << i << ' ';
}
else
{
cout << i << ' ';
}
for (int j = 0; j < COL; j++)
{
cout << gobang_ui[i][j] << ' ';
}
cout << endl;
}
return;
}
int play_chess(char gobang_ui[][COL], int row, int col, char pawn)
{
// 合法性判断
if (gobang_ui[row][col] != ' ')
{
return -1;
}
gobang_ui[row][col] = pawn;
return 1;
}
int check_victory(char gobang_ui[][COL], int row, int col, char pawn)
{
// 方向:水平、垂直、主对角线、副对角线
int d[2][4] = {{0, 1, 1, 1}, {1, 0, 1, -1}};
int new_row = 0;
int new_col = 0;
int count = 0;
// 遍历四个方向
for (int i = 0; i < 4; i++)
{
count = 1;
// 向一个方向查找
for (int j = 1; j < 5; j++)
{
new_row = row + d[0][i] * j;
new_col = col + d[1][i] * j;
if (new_row < 0 || new_row >= ROW || new_col < 0 || new_col >= COL || gobang_ui[new_row][new_col] != pawn)
{
break;
}
count++;
}
// 向相反方向查找
for (int j = 1; j < 5; j++)
{
new_row = row - d[0][i] * j;
new_col = col - d[1][i] * j;
if (new_row < 0 || new_row >= ROW || new_col < 0 || new_col >= COL || gobang_ui[new_row][new_col] != pawn)
{
break;
}
count++;
}
// 连续的棋子数量大于等于5,说明获胜
if (count >= 5)
{
return 1;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/学生优秀模板/game.cpp
|
C++
|
unknown
| 1,995
|
#ifndef _GAME_
#define _GAME_
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROW 15
#define COL 15
/**
* 此函数用于,用户界面初始化
*
* @param gobang_ui 用户提供 char 类型二维数组
*/
void gobang_ui_init(char gobang_ui[][COL]);
/**
* 此函数用于,展示用户界面
*
* @param gobang_ui 用户提供 char 类型二维数组
*/
void show_gobong_ui(char gobang_ui[][COL]);
/**
* 此函数用于,用户落子
*
* @param gobang_ui 用户提供 char 类型二维数组
* @param row 用户提供的 int 类型数据
* @param col 用户提供的 int 类型数据
* @param pawn 用户提供的 char 类型数据
* @return 如果用户落子在成功,返回值为 1 ,否则为 -1.
*/
int play_chess(char gobang_ui[][COL], int row, int col, char pawn);
/**
* 此函数用于,检擦用户死否获得胜利
*
* @param gobang_ui 用户提供的 char 类型二维数组
* @param row 用户提供的 int 类型数据
* @param col 用户提供的 int 类型数据
* @param pawn 用户提供的 char 类型数据
* @return 如果用户获得游戏胜利,返回值为 1 ,否则为 0.
*/
int check_victory(char gobang_ui[][COL], int row, int col, char pawn);
#endif
|
2201_76097352/learning-records
|
ac1/五子棋/学生优秀模板/game.h
|
C++
|
unknown
| 1,309
|
#include <iostream>
#include "game.h"
using namespace std;
int main(int argc, char const *argv[])
{
char gobang_ui[ROW][COL];
char pawn = ' ';
int flag = 1;
int row = 0;
int col = 0;
gobang_ui_init(gobang_ui);
while (1)
{
show_gobong_ui(gobang_ui);
if (flag % 2 == 1)
{
pawn = 'B';
cout << "请黑棋落子,请输入落在下标位置:例如 1 2 : " << endl;
cin >> row >> col;
if (play_chess(gobang_ui, row, col, pawn) == -1)
{
cout << pawn << "方输入错误下标位置,请重新输入" << endl;
}
else
{
flag++;
}
}
else
{
pawn = 'W';
cout << "请白棋落子,请输入落在下标位置:例如 1 2 : " << endl;
cin >> row >> col;
if (play_chess(gobang_ui, row, col, pawn) == -1)
{
cout << pawn << "方输出错误下标位置,请重新输入" << endl;
}
else
{
flag++;
}
}
// 判断是否胜利
if (check_victory(gobang_ui, row, col, pawn))
{
cout << "GOD JOB!!!恭喜" << pawn << "方,获得胜利" << endl;
show_gobong_ui(gobang_ui);
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/五子棋/学生优秀模板/main.cpp
|
C++
|
unknown
| 1,436
|
#include <iostream>
using namespace std;
int max_subscript(int arr[], int capacity)
{
int index = 0;
for (int i = 1; i <= capacity; i++)
{
if (arr[i] > arr[index])
{
index = i;
}
}
return index;
}
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
int a = max_subscript(arr, 10);
cout << "数组中最大值下标为:" << a << endl;
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/01-函数.cpp
|
C++
|
unknown
| 461
|
#include <iostream>
using namespace std;
int temp = 3;
int values = 0;
int replace_arr(int arr[], int capacity);
int follow_up_function(int arr[], int capacity);
int output_function(int arr[], int capacity);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 2, 3, 3, 5, 6, 7, 8, 8, 10};
replace_arr(arr,10);
follow_up_function(arr, 10);
output_function(arr,10);
return 0;
}
int replace_arr(int arr[], int capacity)
{
for(int i = 0; i < capacity ; i++)
{
if(arr[i] != temp)
{
arr[values ++] = arr[i];
}
}
return 0;
}
int follow_up_function(int arr[], int capacity)
{
for(int i = values; i < capacity; i++)
{
arr[i] = 0;
}
return 0;
}
int output_function(int arr[], int capacity)
{
for(int i = 0; i < capacity; i++)
{
cout << arr[i] << " ";
}
}
|
2201_76097352/learning-records
|
ac1/函数/011_删除数组中所有指定元素.cpp
|
C++
|
unknown
| 904
|
#include <iostream>
using namespace std;
/*
int arr[10] = {1, 3, 5, 1, 3, 5, 1, 3, 5, 1};
要求
找出元素 1 在数组中出现的所有下标位置
{0, 3, 6, 9};
*/
int a = 0;
int temp = 10;
//校验
void wrong(int arr[], int capacity);
//决定数组的大小
int number(int arr[], int capacity);
//生成新数组
void subscript_function(int arr[], int capacity, int new_subscalar_array[]);
//输出新数组
void output_function(int new_subscalar_array[], int size);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 1, 3, 5, 1, 3, 5, 1};
wrong(arr,10);
a = number(arr, 10);
int new_subscalar_array[a] = {0};
subscript_function(arr, 10, new_subscalar_array);
output_function(new_subscalar_array, a);
return 0;
}
void wrong(int arr[], int capacity)
{
int worringa = -1;
for(int i = 0; i < capacity; i++)
{
if(arr[i] == temp)
{
worringa = 1;
}
}
if(worringa < 0 )
{
cout << "有问题!!!!!" << endl;
throw new out_of_range("用户提供的下标位置超出有效范围!");
}
}
int number(int arr[], int capacity)
{
int count = 0;
for(int i = 0; i < capacity; i++)
{
if(arr[i] == temp)
{
count++;
}
}
return count;
}
void subscript_function(int arr[], int capacity, int new_subscalar_array[])
{
int index = 0;
for(int i = 0; i < capacity; i++)
{
if(arr[i] == temp)
{
new_subscalar_array[index++] = i;
}
}
}
void output_function(int new_subscalar_array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << new_subscalar_array[i] << " ";
}
}
|
2201_76097352/learning-records
|
ac1/函数/013_找出指定元素在数组中的所有下标位置,存储到另一个数组中.cpp
|
C++
|
unknown
| 1,757
|
#include <iostream>
using namespace std;
/*
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
用户指定开始下标为 2,结束下标为 6,
{5, 7, 9, 2}
【隐含一定的条件约束】
1. 截取数据,结束下标对应的元素在新数组中不存在,要头不要尾 [begin, end)
2. 用户指定的起始下标和终止下标必须在合法范围以内。
3. 需要根据用户提供的下标范围,创建一个新的数组,暂时使用 C99 以上版本能力,完成一个临时的数组
*/
void wrong(int arr[], int capacity, int begin, int end);
int number(int begin, int end);
void extraction_function(int arr[], int block[], int begin, int end);
void out_function(int block[], int size);
int main(int argc, char const *argv[])
{
int begin = 2;
int end = 6;
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
wrong(arr, 10, begin, end);
int block[end - begin] = {0};
extraction_function(arr, block, 2, 6);
out_function(block, 4);
return 0;
}
void wrong(int arr[], int capacity, int begin, int end)
{
if (begin < 0 || end > begin || end > capacity)
{
cout << "有问题!!!!!" << endl;
exit(1);
}
}
void extraction_function(int arr[], int block[], int begin, int end)
{
int temp = 0;
for (int i = begin; i < end; i++)
{
block[temp++] = arr[i];
}
}
void out_function(int block[], int size)
{
for (int i = 0; i < size; i++)
{
cout << block[i] << " ";
}
cout << endl;
}
|
2201_76097352/learning-records
|
ac1/函数/014_用户指定起始下标和终止下标位置截取数组中的数据内容得到新数组.cpp
|
C++
|
unknown
| 1,530
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
for (int i = 0; i < 10 / 2; i++)
{
/*
int temp = arr[i];
arr[i] = arr[10 - 1 - i];
arr[10 - 1 - i] = arr[i];
*/
arr[i] += arr[10 - i - 1];
arr[10 - 1 - i] = arr[i] - arr[10 - 1 - i];
arr[i] -= arr[10 - 1 - i];
}
for (int i = 0; i < 10; i++)
{
cout << arr[i] << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/05-数组元素逆序.cpp
|
C++
|
unknown
| 527
|
# include <iostream>
using namespace std;
void inverse_order_of_elements (int arr[],int capacity);
int export_it (int arr[],int capacity);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
inverse_order_of_elements(arr,10);
export_it (arr,10);
return 0;
}
void inverse_order_of_elements (int arr[],int capacity)
{
for(int i = 0; i < capacity / 2; i++)
{
arr[i] += arr[10 - i - 1];
arr[10 - 1 - i] = arr[i] - arr[10 - 1 - i];
arr[i] -= arr[10 - 1 - i];
}
}
int export_it (int arr[],int capacity)
{
for(int i = 0; i < capacity; i++)
{
cout << arr[i] <<endl;
}
}
|
2201_76097352/learning-records
|
ac1/函数/055-函数数组元素逆序.cpp
|
C++
|
unknown
| 687
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
int a,b,c;
c=999;
while(c)
{
cout <<"输入需要被替换掉的下标:"<< endl;
cin >> a;
if(a <= 9 && a >= 0)
{
cout <<"输入使用的新元素:"<< endl;
cin >> b;
arr[a] = b;
cout <<"替换成功"<< endl;
break;
}
else
{
cout <<"请重新输入需要被替换掉的下标!"<< endl;
cout << "输入0结束!输入其他继续 "<< endl;
cin >> c;
}
}
for(int i = 0; i <= 9; i++)
{
cout << arr[i] << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/06- 使用指定元素,替换指定下标元素.cpp
|
C++
|
unknown
| 768
|
# include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/066- 函数使用指定元素,替换指定下标元素.cpp
|
C++
|
unknown
| 163
|
# include <iosstream>
using namespace std;
/*
数组案例
完成代码,给予任意 int 类型数据,找出目标 int 类型数组中最大值对应的下标位置,
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
数组中最大值下标位置为 9
*/
int main(int argc, char const*argv[])
{
/**
* 搜索最大值下标位置的数组
*/
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
/*
定义一个变量用于储存下标,初始化为 0 ,假设数组中下标为 0 的元素是整个
数组的最大值的下标位置。
*/
int index = 0;
/*
利用 for 循环遍历整个数组,如果发现数据大于 index 储存下标位置对应元素
index 储存对应下标位置,知道数组的末尾,可以确定 index 对应元素就是数组
中最大值元素的下标位置。
tips:当前循环变量 i 可以从 1 开始,因为 index 初始化数据为 0 ,如果 i 从
0 开始,第一次存循环中情况是 arr[0] > arr[0] 操作无意义,浪费循环次数,小优化
将 i 从 1 开始。
*/
for (int i = 1; i < 10; i++)
{
/*
如果下标 i 对应元素大于下标 index 元素,
index 存储当前 i。
*/
if (arr[i] > arr[index])
{
index = i;
}
}
cou <<"数组中最大值对应元素下标位置 : "<< index << endl;
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/a01-练习找出数组中最大值对应的下标位置.cpp
|
C++
|
unknown
| 1,386
|
#include <iostream>
using namespace std;
/*
数组案例
完成代码,给予任意 int 类型数据,找出目标 int 类型数组中最小值对应的下标位置
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
数组中最小值下标位置为
*/
int main(int argc, char const *argv[])
{
/**
* 搜索最小值下标位置的目标 int 类型数组,数组容量为 10
*/
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
/**
* 用于记录当前数组中最小值对应的小标位置,同时初始化为 0
* 以当前数组中下标为 0 的元素作为参照物进行使用。
*/
int index = 0;
/*
利用循环遍历整个数组,如果发现数组中下标为 i 的元素
小于 index 下标对应的元素,index 存储对应的下标 i
*/
for (int i = 1; i < 10; i++)
{
if (arr[index] > arr[i])
{
index = i;
}
}
cout << "最小值对应的下标位置 : " << index << ednl;
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/a02-找出数组中最小值下标位置.cpp
|
C++
|
unknown
| 1,028
|
# include <iostream>
using namespace std;
/*
数组案例
int arr[10] = {11, 3, 5, 7, 9, 2, 5, 6, 8, 10};
用户提供数据 5 对应下标位置 2
用户提供数据 20 反馈数据 -1 ,采用非法下标方式告知数据未找到
*/
int main(int argc, char const *argv[])
{
/**
* 搜索数据的目标 int 类型数组,容量为 10
*/
int arr[10] = {11, 3, 5, 7, 9, 2, 5, 6, 8, 10};
/**
* 搜索的目标元素
*/
int target = 5;
/*
1. 定义一个变量 index ,用于储存目标元素在数组中第一次出现的下标位置
index 可以作为【标记 + 数据记录】两个功能的变量。
如果当前数据找到,index 的储存数据结果一定是大于等于 0
如果按照题目要求,目标数据未找到,index 对应的是 -1
直接将 inddex 初始化为 -1 ,利用数据的互质性质进行后续条件判断
在 for 循环中,找到目标元素,index 重新赋值一定不为 -1 ,如果没有
找到目标元素,index 依然是 -1 ,可以条件标记。
*/
int index = -1;
/*
2. 利用 for 循环遍历整个数组,如果找到了和当前目标数组 target 一直的元素
index 赋值对应的下标位置,同时利用 break 跳出循环结构
*/
for (int i = 0; i < 10; i++)
{
if(target == arr[i])
{
index = i;
break;
}
}
/*
最终展示
*/
if (index > -1)
{
cout << "目标元素" << target
<< ", 在数组中第一次出现下标的位置 : " << index << endl;
}
else
{
cout << "目标元素未找到!! Target Not Found!" << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/a03-找出指定元素第一次出现的下标位置.cpp
|
C++
|
unknown
| 1,722
|
# include <iostream>
using namespace std;
/*
案例数组
int arr[10] = {11, 3, 5, 7, 9, 2, 5, 6, 8, 10};
用户数据提供 5 对应下标位置 6
用户数据提供 20 反馈数据 -1 ,采用非法下标方式告知数据未找到
*/
int main(int argc, char const *argv[])
{
/**
* 搜索数据的目标 int 类型数据, 容量为 10
*/
int arr[10] = {11, 3, 5, 7, 9, 2, 5, 6, 8, 5};
/**
* 目标搜索元素,找出当前元素在宿素数组中最后一次出现的下标位置
*/
int target = 5;
/*
1. 定义一个变量 index 初始化为 -1,如果在搜索过程中,找到了
目标元素,当先 index 数据 >= 0,如果没有找到,index 依然是-1
*/
int index = -1;
/*
2. 利用 for 循环,从数组中最后一个有效元素下标位置开始,向前遍历
找到目标元素所在下标位置
*/
for (int i = 10 - 1; i >= 0; i++)
{
if (target == arr[i])
{
index = i;
break;
}
}
/*
搜索结果展示
*/
if (index >-1)
{
cout << "目标元素 " << target
<< ", 数组在最后一次出现的下标位置 : " << index << endl;
}
else
{
cout << "目标元素未找到 !!Target Not Found!!" << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/a04-找出指定元素最后一次出现的下标位置.cpp
|
C++
|
unknown
| 1,306
|
#include <iostream>
using namespace std;
/*
int arr[10] = {1, 3, 5 7, 9, 2, 4, 6, 8, 10};
逆序之后的数据
arr ==> {10, 8, 6, 4, 2, 9, 7, 5, 3, 1};
数据交换位置的次数 = 数组容量 / 2
*/
int main(int argc, char const *argv[])
{
/**
* 逆序数组的目标 int 类型数组,数组容量为 10
*/
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
/*
利用 for 循环,遍历数组,循环次数 = 数组容量 、 2
进行数据交换操作
*/
for (int i = 0; i < 10 / 2; i++)
{
/*
int temp = arr[i];
arr[i] = arr[10 - 1 - i];
arr[10 - 1 - i] = temp;
*/
/*
当前代码实现相较于以上代码格式,可以节约 4 个字节的内存空间
少定义一个 int 类型变量
*/
arr[i] += arr[10 -1 - i];
arr[10 - 1 - i] = arr[i] - arr[10 - 1 - i];
arr[i] -= arr[10 - 1 - i] ;
}
for (int i = 0; i < 10; i++)
{
cont << "arr[" << i << "] : " << arr[i] <<endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/函数/a05-数组元素逆序.cpp
|
C++
|
unknown
| 1,011
|
#include <iostream>
using namespace std;
/**
* 在控制台展示用户提供的 int 类型数据
*
* @param arr 用户提供的 int 类型数组
* @param capacity 用户提供数组对应的容量
*/
void show_int_arry(int arr[], int capacity);
/*
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
用户指定替换元素的下标位置 5,替换使用的新元素 20,最红结果
1.需要知晓被替换掉的元素情况
2.数组的数据内容替换之后
{1, 3, 5, 7, 9, 20,4, 6, 8,10}
【隐含一定的条件约束】
对用户提供的xia
*/
int main(int argc, char const *argv[])
{
/**
* 替换制定下标元素的原 int 类型数据,数组容量为 10
*/
int arr[10] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
/**
* 用户指定下标位置
*/
int index = 2;
/**
* 用户指定替换目标元素使用的新数据
* target new_value new_element
*/
int new_velue = 20;
/*
1.用户提供下标位置的合法性判断,当前数组容量为 10,对应下标
有效位置是 0 ~ 9,如果用户提供的下标位置超出当前范围,后续替换操作不执行
*/
if (index < 0 || index > 10 -1)
{
// 给予用户必要的操作提示
cout << "亲,您提供的下表数据有错 ";
// 利用 return 关键字对当前函数进行退出操作。
return 0;
}
/*
2. 根据用户指定的下标位置,将被替换掉元素进行提取操作
*/
int old_value = arr[index];
/*
3. 使用 new_value 覆盖指定下标元素
*/
arr[index] = new_velue;
/*
相关数据展示
a. 被替换的元素
b. 当前数组的数据情况
*/
cout << "被替换的元素为 : ‘" << old_value << endl;
cout << "当前数组的情况 :";
show_int_arry(arr, 10);
return 0;
}
void show_int_array(int arr[], int capacity)
{
cout << '[';
for (int i = 0; i < capacity - 1; i++)
{
cout << arr[i] << ", ";
}
if (0 == capacity)
{
cout << ']';
}
else\
{
cout << arr[capacity - 1] << ']' << endl;
}
}
|
2201_76097352/learning-records
|
ac1/函数/a06-使用指定元素替换指定下标元素.cpp
|
C++
|
unknown
| 2,222
|
#include <iostream>
/*
引入目标头文件
*/
#include "test.h"
using namespace std;
int main(int argc, char const *argv[])
{
/*
可以直接调用在 test.h 中声明的函数
*/
int ret = my_add(10, 20);
cout << "ret : " << ret << endl;
int arr[5] = {1, 3, 5, 7, 9};
show_int_array(arr, 5);
return 0;
}
|
2201_76097352/learning-records
|
ac1/分组模板/01-main.cpp
|
C++
|
unknown
| 344
|
#include "test.h"
/*
引入必要的命名空间,当前 std 命名空间不可以在头文件中声明引入。
*/
using namespace std;
int my_add(int n1, int n2)
{
return n1 + n2;
}
void show_int_array(int arr[], int capacity)
{
if (0 == capacity)
{
cout << "[]" << endl;
}
cout << '[';
for (int i = 0; i < capacity - 1; i++)
{
cout << arr[i] << ", ";
}
cout << arr[capacity - 1] << ']' << endl;
}
|
2201_76097352/learning-records
|
ac1/分组模板/test(1).cpp
|
C++
|
unknown
| 463
|
#ifndef _TEST_
#define _TEST_
/*
资源导入,当前代码实现有可能需要其他资源支持,需要导入
其他资源的对应头文件,例如 系统头文件,第三方头文件
*/
#include <iostream>
/**
* 自定义 add 函数,用户提供两个 int 类型数据,返回在是两个
* int 类型数据之和
*
* @param n1 用户提供的 int 类型数据
* @param n2 用户提供的 int 类型数据
* @return 两个 int 类型数据之和
*/
int my_add(int n1, int n2);
/**
* 在控制台展示用户提供的 int 类型数组
*
* @param arr 用户提供用于展示的 int 类型数组
* @param capacity 用户提供数组对应的容量
*/
void show_int_array(int arr[], int capacity);
#endif
|
2201_76097352/learning-records
|
ac1/分组模板/test(2).h
|
C++
|
unknown
| 737
|
#include <iostream>
#include "minesweeper.h"
using namespace std;
int main(int argc, char const *argv[])
{
char mine_ui[ROW][COL] = {'\0'};
char mine_area[ROW][COL] = {'\0'};
mine_ui_init(mine_ui);
mine_area_init(mine_area);
show_mine_ui(mine_area);
int ret = 0;
int flag = 1;
int choose = 0;
int row_index = 0;
int col_index = 0;
// 已使用的标记次数
int used_mark_count = 0;
// 表示成功次数
int mark_success_count = 0;
while (1)
{
show_mine_ui(mine_ui);
cout << "请输入您的选择: \n1. 探索.\n2. 标记.\n3. 取消标记 " << endl;
cin >> choose;
switch (choose)
{
case EXPLORE:
cout << "请输入探索的雷区下标位置,例如 1 2 : ";
cin >> row_index >> col_index;
flag = explore_mine_area(mine_ui, mine_area, row_index, col_index);
break;
case MARK:
cout << "请输入标记为雷区的下标位置,例如 1 2 : ";
cin >> row_index >> col_index;
/*
ret 存储当前标记操作对应的结果情况
如果提供下标错误,ret 结果为 -1,标记失败结果为 0,标记成功结果为 1
*/
ret = mark_mine(mine_ui, mine_area, row_index, col_index);
/*
如果 ret 结果为 -1 表示当前提供的下标不合法,【标记未使用,标记成功次数不影响】
如果 ret 结果为 0 表示标记位置非雷区,【标记已使用,标记成功次数不影响/标记成功次数 += 0】
如果 ret 结果为 1 表示标记位置为雷区,【标记已使用,标记成功次数 += 1】
*/
if (ret != -1)
{
used_mark_count += 1;
mark_success_count += ret;
}
break;
default:
cout << "其他操作" << endl;
break;
}
if (!flag)
{
cout << "GAME OVER!" << endl;
break;
}
if (mark_success_count == used_mark_count && mark_success_count == MINE_COUNT)
{
cout << "Good Job!!! 游戏胜利!" << endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/扫雷范本/04_标记函数演示.cpp
|
C++
|
unknown
| 2,324
|
#include "minesweeper.h"
using namespace std;
void mine_ui_init(char mine_ui[][COL])
{
#if 0
// 【必会点】基本实现
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
mine_ui[i][j] = '*';
}
}
#endif
/*
C 语言内存设置函数,需要提供给函数的参数是目标内存首地址,
每一个字节对应的数据内容,和总计设置内存的字节数。
【家政函数】
告知家政公司你的地址
打扫的标准
面积
【内存操作,后续学习重点】
void mine_area_init(char mine_area[][COL]);
*/
memset(mine_ui, '*', ROW * COL);
}
void mine_area_init(char mine_area[][COL])
{
// 整个雷区所有的元素位置都是字符 '0'
memset(mine_area, '0', ROW * COL);
/*
当前函数的功能是设置相关的随机数原则 time(0) 是
随机数种子因素,对应当前时间,单位可以认为是毫米
*/
srand(time(0));
/**
* 行下标变量
*/
int row_index = 0;
/**
* 列下标变量
*/
int col_index = 0;
/**
* 当前布雷成功的次数,因为 row_index 和 col_index 都需要通过
* 随机数生成,有可能会导致出现同一个位置重复布雷情况,利用
* current_mine_count 记录布雷成功次数
*/
int current_mine_count = 0;
/*
如果地雷布置成功的次数 不等于 当前雷区限制的地雷总数,循环继续
*/
while (current_mine_count != MINE_COUNT)
{
row_index = rand() % 10;
col_index = rand() % 10;
cout << "row_index : " << row_index << ", col_index : " << col_index << endl;
// 如果对应下标位置在真实雷区数组中不是地雷
if (mine_area[row_index][col_index] != '#')
{
/*
首先完成
1. 真实雷区数组对应下标位置进行赋值 '#' 操作,表示为地雷
2. 布置成功的地雷个数 += 1
*/
mine_area[row_index][col_index] = '#';
current_mine_count += 1;
/*
将新放置地雷的周边 8 个元素位置进行 += 1 操作
以下情况不做任何处理
1. 周边位置为地雷
2. 超出有效的雷区范围
*/
#if 0
for (int i = row_index - 1; i <= row_index + 1; i++)
{
for (int j = col_index - 1; j <= col_index + 1; j++)
{
if (i < 0 || j < 0 || i > ROW - 1 || j > COL - 1 || '#' == mine_area[i][j])
{
continue;
}
else
{
mine_area[i][j] += 1;
}
}
}
#endif
#if 1
for (int i = (row_index - 1 >= 0 ? row_index - 1 : 0);
i <= (row_index + 1 > ROW - 1 ? ROW - 1 : row_index + 1);
i++)
{
cout << "i : " << i << endl;
for (int j = (col_index - 1 >= 0 ? col_index - 1 : 0);
j <= (col_index + 1 > COL - 1 ? COL - 1 : col_index + 1);
j++)
{
cout << "j : " << j << endl;
if (mine_area[i][j] != '#')
{
mine_area[i][j] += 1;
}
}
}
#endif
}
}
}
void show_mine_ui(char mine_ui[][COL])
{
cout << " 1 2 3 4 5 6 7 8 9 10" << endl;
for (int i = 0; i < ROW; i++)
{
if (i < 9)
{
cout << ' ' << i + 1 << ' ';
}
else
{
cout << i + 1 << ' ';
}
for (int j = 0; j < COL; j++)
{
cout << mine_ui[i][j] << ' ';
}
cout << endl;
}
}
int explore_mine_area(char mine_ui[][COL],
char mine_area[][COL],
int row_index,
int col_index)
{
/*
判断用户提供的数据是否合法
*/
if (row_index < 1 || row_index > ROW || col_index < 1 || col_index > COL)
{
cout << "用户提供下标数据不合法!" << endl;
return 0;
}
/*
用户提供的下标数据进行二次处理,符合数组下标要求
*/
row_index -= 1;
col_index -= 1;
/*
标记变量,用于记录当前用户探索的雷区的情况
如果探索失败,flag 赋值为 0,如果探索成功 flag 依然为 1
*/
int flag = 1;
if ('#' == mine_area[row_index][col_index])
{
// 如果是地雷,flag 重新赋值为 0
flag = 0;
}
else
{
// 如果不是地雷,将真实雷区对应的数据,赋值给当前的用户界面对应下标位置
mine_ui[row_index][col_index] = mine_area[row_index][col_index];
}
return flag;
}
int mark_mine(char mine_ui[][COL],
char mine_area[][COL],
int row_index,
int col_index)
{
/*
判断用户提供的数据是否合法
如果用户指定下标位置非星号加密区域,无法进行标记操作,照样返回 -1
*/
if (row_index < 1 || row_index > ROW || col_index < 1 || col_index > COL
|| mine_ui[row_index - 1][col_index - 1] != '*')
{
cout << "用户提供下标数据不合法!" << endl;
return -1;
}
// 对用户提供的下标数据进行二次处理
row_index -= 1;
col_index -= 1;
// 用户界面对应下标位置直接赋值 'F'
mine_ui[row_index][col_index] = 'F';
/*
在真实雷区数组中,用户指定下标位置是一个地雷,当前 return 结果为 1
如果不是地雷,return 结果为 0,满足当前函数声明要求的返回结果
*/
return '#' == mine_area[row_index][col_index];
}
|
2201_76097352/learning-records
|
ac1/扫雷/扫雷范本/minesweeper.cpp
|
C++
|
unknown
| 6,019
|
#ifndef _MINESWEEPER_
#define _MINESWEEPER_
#include <iostream>
/*
C 语言头文件三剑客
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
利用宏常量定义整个雷区大小
ROW 雷区行数
COL 雷区列数
MINE_COUNT 雷区地雷个数
*/
#define ROW 10
#define COL 10
#define MINE_COUNT 1
#define EXPLORE 1
#define MARK 2
#define CANCEL_MARK 3
/*
第一个功能函数: 用户游戏界面初始化函数
*/
/**
* 用户界面初始化函数,参数是一个 char 类型的二维数组,要求
* 每一个元素位置都是字符 '*' 号
*
* @param mine_ui 用户游戏界面
*/
void mine_ui_init(char mine_ui[][COL]);
/**
* 展示用户游戏界面,也可以对雷区数据进行展示
*
* @param mine_ui 用户游戏界面或者雷区数组
*/
void show_mine_ui(char mine_ui[][COL]);
/**
* 雷区初始化函数,利用随机数方式对雷区布雷位置进行下标确定,周边
* 其他区不超过雷区范围,同时不是地雷的区域,都需要 += 1
*
* @param mine_area 真实雷区数组
*/
void mine_area_init(char mine_area[][COL]);
/**
* 探索函数实现: 用户提供探索的下标位置,需要从真实雷区校验当前探索
* 是否踩雷
* 如果踩雷,返回 0
* 如果没有踩雷,需要将真实雷区中对应数字字符,拷贝到用户界面,返回 1
*
* @param mine_ui 用户界面 char 类型二维数组
* @param mine_area 真实雷区数据 char 类型二维数组
* @param row_index 用户指定探索的行下标。用户提供数据为 1 ~ 10 有效数据,需要二次处理
* @param col_index 用户指定探索的列下标。用户提供数据为 1 ~ 10 有效数据,需要二次处理
* @return 如果探索成功返回 1,否则返回 0
*/
int explore_mine_area(char mine_ui[][COL],
char mine_area[][COL],
int row_index,
int col_index);
#if 0
/*
标记操作,需要和真实雷区进行比对,当前函数有三种执行结果
1. 用户提供下标数据不合法
2. 用户提供下标位置标记成功,对应位置确实为雷区
3. 用户提供下标位置标记失败,对应位置非地雷
*/
#endif
/**
* 标记雷区操作,需要用户提供对应的下标位置,和真实雷区进行校验
* 存在三种情况返回结果。
*
* @param mine_ui 用户界面 char 类型二维数组
* @param mine_area 真实雷区数据 char 类型二维数组
* @param row_index 用户指定探索的行下标。用户提供数据为 1 ~ 10 有效数据,需要二次处理
* @param col_index 用户指定探索的列下标。用户提供数据为 1 ~ 10 有效数据,需要二次处理
* @return 返回结果为 int 类型,存在三种情况
* 1. 用户提供下标数据不合法,返回 -1
* 2. 用户提供下标位置标记成功,对应位置确实为雷区 ,返回 1
* 3. 用户提供下标位置标记失败,对应位置非地雷,返回 0
*/
int mark_mine(char mine_ui[][COL],
char mine_area[][COL],
int row_index,
int col_index);
#endif
|
2201_76097352/learning-records
|
ac1/扫雷/扫雷范本/minesweeper.h
|
C++
|
unknown
| 3,204
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
// 定义一个 3x3 的二维数组
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for (int i = -1; i < 3; ++i)
{
for (int j = -1; j < 3; ++j)
{
cout << arr[i][j] ;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/练习/01_随机数.cpp
|
C++
|
unknown
| 353
|
#include <iostream>
using namespace std;
int main()
{
// 定义二维数组的行数和列数
const int rows = 9;
const int cols = 9;
// 声明并初始化用户二维数组
char arr0[rows][cols];
// 使用嵌套的 for 循环遍历数组
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
// 将数组元素赋值为星号
arr[i][j] = '*';
cout << arr0[i][j] <<" ";
}
cout << endl;
}
//==========================================================
//声明并初始化雷区二维数组
char arr[10][10]; // 定义 10*10 的二维字符数组
srand(static_cast<unsigned int>(time(NULL))); // 初始化随机数种子
// 先将数组元素全部初始化为空格
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++) {
arr[i][j] = ' ';
}
}
// 随机选取 10 个位置赋值为 '#'
for (int k = 0; k < 10; k++)
{
int row = rand() % 10; // 随机生成行号,范围是 0 到 9
int col = rand() % 10; // 随机生成列号,范围是 0 到 9
arr[row][col] = '#';
}
// 用户输入 F 坐标
int a = 0;
int b = 0;
cin << "请输入(横坐标)(纵坐标)" << a << b << endl;
if (a == row && b == col)
{
}
// 输出数组
/*
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; ++j)
{
std::cout << arr[i][j] << " ";
}
std::cout << std::endl;
}
*/
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/练习/02_扫雷.cpp
|
C++
|
unknown
| 1,570
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// 定义雷区大小
const int rols = 10;
const int cols = 10;
// 定义雷的数量
const int NUM_MINES = 10;
/**
* @param gameBoard 界面数组界面
* @param mineBoard 地雷数组界面
*/
// 初始化数组
void initialise(char gameBoard[rols][cols], char mineBoard[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
gameBoard[i][j] = '*';
mineBoard[i][j] = '0';
}
}
}
// 布雷
void arrange(char mineBoard[rols][cols])
{
srand(time(NULL));
int minesPlaced = 0;
while (minesPlaced < NUM_MINES)
{
int row = rand() % rols;
int col = rand() % cols;
if (mineBoard[row][col] == '0')
{
mineBoard[row][col] = '#';
minesPlaced++;
}
}
}
// 计算某个位置周围的雷的数量
int number_mine(char mineBoard[rols][cols], int row, int col)
{
int count = 0;
for (int i = row - 1; i <= row + 1; i++)
{
for (int j = col - 1; j <= col + 1; j++)
{
if (i >= 0 && i < rols && j >= 0 && j < cols && mineBoard[i][j] == '#')
{
count++;
}
}
}
return count;
}
// 探索操作
void explore(char gameBoard[rols][cols], char mineBoard[rols][cols], int row, int col, int rols, int cols)
{
if (mineBoard[row][col] == '#')
{
std::cout << "Game Over" << std::endl;
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
gameBoard[i][j] = mineBoard[i][j];
}
}
return;
}
int numMines = mineBoard[rols][cols];
gameBoard[row][col] = numMines + '0';
}
// 标记雷区
void mark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == '*')
{
gameBoard[row][col] = 'F' + '0';
}
}
// 取消标记
void unmark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == 'F')
{
gameBoard[row][col] = '*';
}
}
// 打印游戏界面
void printBoard(char board[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
if (board[i][j] == '#')
{
std::cout << "# ";
}
else
{
int numMines = number_mine(board, i, j);
std::cout << numMines << " ";
}
}
std::cout << std::endl;
}
}
void printBoardFule(char board[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
cout << board[i][j] << " ";
}
std::cout << std::endl;
}
}
int main()
{
char gameBoard[rols][cols];
char mineBoard[rols][cols];
initialise(gameBoard, mineBoard);
arrange(mineBoard);
int markedCount = 0;
int correct_Marked_Count = 0;
while (true)
{
std::cout << "游戏开始: " << std::endl;
printBoard(mineBoard);
cout << endl;
printBoardFule(gameBoard);
std::cout << "输入行,列 和动作(e: 探索, f: 标记, u: 取消标记): ";
std::cout << std::endl;
int row, col;
char action;
std::cin >> row >> col >> action;
if (row < 0 || row >= rols || col < 0 || col >= cols)
{
std::cout << "输入的行或列超出范围,请重新输入" << std::endl;
continue;
}
if (action == 'e')
{
gameBoard[row][col] = mineBoard[row][col];
explore(gameBoard, mineBoard, row, col, rols, cols);
}
else if (action == 'f')
{
mark_Mine(gameBoard, row, col);
markedCount++;
if (mineBoard[row][col] == '#')
{
correct_Marked_Count++;
}
}
else if (action == 'u')
{
unmark_Mine(gameBoard, row, col);
markedCount--;
}
cout << "correct_Marked_Count : " << correct_Marked_Count <<
", markedCount : " << markedCount <<
", NUM_MINES : " << NUM_MINES << endl;
if (correct_Marked_Count == NUM_MINES && markedCount == NUM_MINES)
{
std::cout << "You Win!!!!!" << std::endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/练习/03_扫雷.cpp
|
C++
|
unknown
| 4,521
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// 定义雷区大小
const int rols = 10;
const int cols = 10;
// 定义雷的数量
const int NUM_MINES = 20;
/**
* @param gameBoard 界面数组界面
* @param mineBoard 地雷数组界面
*/
// 初始化数组
void initialise(char gameBoard[rols][cols], char mineBoard[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
gameBoard[i][j] = '*';
mineBoard[i][j] = '0';
}
}
}
// 布雷
void arrange(char mineBoard[rols][cols])
{
srand(time(NULL));
int minesPlaced = 0;
while (minesPlaced < NUM_MINES)
{
int row = rand() % rols;
int col = rand() % cols;
if (mineBoard[row][col] == '0')
{
mineBoard[row][col] = '#';
minesPlaced++;
}
}
}
// 计算某个位置周围的雷的数量
int number_mine(char mineBoard[rols][cols], int row, int col)
{
int count = 0;
for (int i = row - 1; i <= row + 1; i++)
{
for (int j = col - 1; j <= col + 1; j++)
{
if (i >= 0 && i < rols && j >= 0 && j < cols && mineBoard[i][j] == '#')
{
count++;
}
}
}
return count;
}
// 探索操作
void explore(char gameBoard[rols][cols], char mineBoard[rols][cols], int row, int col)
{
if (mineBoard[row][col] == '#')
{
std::cout << "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl;
return;
}
int numMines = number_mine(mineBoard, row, col);
gameBoard[row][col] = numMines +'0';
}
// 标记雷区
void mark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == '*')
{
gameBoard[row][col] = 'F';
}
}
// 取消标记
void unmark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == 'F')
{
gameBoard[row][col] = '*';
}
}
// 打印游戏界面
void printBoard(char board[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
std::cout << board[i][j] << " ";
}
std::cout << std::endl;
}
}
int main()
{
char gameBoard[rols][cols];
char mineBoard[rols][cols];
initialise(gameBoard, mineBoard);
arrange(mineBoard);
int markedCount = 0;
int correct_Marked_Count = 0;
while (true)
{
std::cout << "游戏开始: " << std::endl;
printBoard(mineBoard);
std::cout << std::endl;
printBoard(gameBoard);
std::cout <<"输入行,列 和动作(e: 探索, f: 标记, u: 取消标记): ";
std::cout << std::endl;
int row, col;
char action;
std::cin >> row >> col >> action;
if (row < 0 || row >= rols || col < 0 || col >= cols)
{
std::cout << "输入的行或列超出范围,请重新输入" << std::endl;
continue;
}
if (action == 'e')
{
explore(gameBoard, mineBoard, row, col);
}
else if (action == 'f')
{
mark_Mine(gameBoard, row, col);
markedCount++;
if (mineBoard[row][col] == '*')
{
correct_Marked_Count++;
}
}
else if (action == 'u')
{
unmark_Mine(gameBoard, row, col);
markedCount--;
}
if(correct_Marked_Count == NUM_MINES && markedCount == NUM_MINES)
{
std::cout << "You Win!!!!!" << std::endl
<< "You Win!!!!!" << std::endl
<< "You Win!!!!!" << std::endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/练习/06.cpp
|
C++
|
unknown
| 4,015
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// 定义雷区大小
const int rols = 10;
const int cols = 10;
// 定义雷的数量
const int NUM_MINES = 20;
/**
* @param gameBoard 界面数组界面
* @param mineBoard 地雷数组界面
*/
// 初始化数组
void initialise(char gameBoard[rols][cols], char mineBoard[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
gameBoard[i][j] = '*';
mineBoard[i][j] = '0';
}
}
}
// 布雷
void arrange(char mineBoard[rols][cols])
{
srand(time(NULL));
int minesPlaced = 0;
while (minesPlaced < NUM_MINES)
{
int row = rand() % rols;
int col = rand() % cols;
if (mineBoard[row][col] == '0')
{
mineBoard[row][col] = '#';
minesPlaced++;
}
}
}
// 计算某个位置周围的雷的数量
int number_mine(char mineBoard[rols][cols], int row, int col)
{
int count = 0;
for (int i = row - 1; i <= row + 1; i++)
{
for (int j = col - 1; j <= col + 1; j++)
{
if (i >= 0 && i < rols && j >= 0 && j < cols && mineBoard[i][j] == '#')
{
count++;
}
}
}
return count;
}
// 打印游戏界面
void printBoard(char board[rols][cols])
{
for (int i = 0; i < rols; i++)
{
for (int j = 0; j < cols; j++)
{
std::cout << board[i][j] << " ";
}
std::cout << std::endl;
}
}
void expand_blank_area(char gameBoard[][cols],
char mineBoard[][cols],
int row,
int col)
{
// 递归函数首先完成终止条件,而且有时候终止条件需要分开完成。
// 1. 【终止条件】下标越界
if (rols < 0 || rols > row - 1 || cols < 0 || cols > col - 1)
{
return;
}
// 2. 【终止条件】当前用户界面已经进行了展开限制,不再是 '*'
if (gameBoard[rols][cols] != '*')
{
return;
}
// 3. 【终止条件】真实雷区中,对应下标位置已经不是 0, 需要终止展开,同时将对应
// 真实雷区数据赋值给当前的用户界面
if (mineBoard[rols][cols] >= '1' && mineBoard[rols][cols] <= '8')
{
gameBoard[rols][cols] = mineBoard[rols][cols];
return;
}
if ('0' == mineBoard[rols][cols])
{
/*
其他情况下。当前真实雷区的数据一定的是字符 0 ,直接进行赋值到用户界面操作,同时
开启【递归模式】进行展开操作
*/
gameBoard[rols][cols] = '_';
expand_blank_area(gameBoard, mineBoard, row, col - 1);
expand_blank_area(gameBoard, mineBoard, row, col + 1);
expand_blank_area(gameBoard, mineBoard, row + 1, col - 1);
expand_blank_area(gameBoard, mineBoard, row + 1, col);
expand_blank_area(gameBoard, mineBoard, row + 1, col + 1);
expand_blank_area(gameBoard, mineBoard, row - 1, col - 1);
expand_blank_area(gameBoard, mineBoard, row - 1, col);
expand_blank_area(gameBoard, mineBoard, row - 1, col + 1);
}
}
// 探索操作
void explore(char gameBoard[rols][cols], char mineBoard[rols][cols], int row, int col)
{
if (mineBoard[row][col] == '#')
{
std::cout << "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl
<< "Game Over$$$$$$" << std::endl;
return;
}
expand_blank_area(gameBoard, mineBoard, row, col);
printBoard(gameBoard);
}
// 标记雷区
void mark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == '*')
{
gameBoard[row][col] = 'F';
}
}
// 取消标记
void unmark_Mine(char gameBoard[rols][cols], int row, int col)
{
if (gameBoard[row][col] == 'F')
{
gameBoard[row][col] = '*';
}
}
int main()
{
char gameBoard[rols][cols];
char mineBoard[rols][cols];
initialise(gameBoard, mineBoard);
arrange(mineBoard);
int markedCount = 0;
int correct_Marked_Count = 0;
while (true)
{
std::cout << "游戏开始: " << std::endl;
printBoard(mineBoard);
std::cout << std::endl;
printBoard(gameBoard);
std::cout <<"输入行,列 和动作(e: 探索, f: 标记, u: 取消标记): ";
std::cout << std::endl;
int row, col;
char action;
std::cin >> row >> col >> action;
if (row < 0 || row >= rols || col < 0 || col >= cols)
{
std::cout << "输入的行或列超出范围,请重新输入" << std::endl;
continue;
}
if (action == 'e')
{
explore(gameBoard, mineBoard, row, col);
}
else if (action == 'f')
{
mark_Mine(gameBoard, row, col);
markedCount++;
if (mineBoard[row][col] == '*')
{
correct_Marked_Count++;
}
}
else if (action == 'u')
{
unmark_Mine(gameBoard, row, col);
markedCount--;
}
if(correct_Marked_Count == NUM_MINES && markedCount == NUM_MINES)
{
std::cout << "You Win!!!!!" << std::endl
<< "You Win!!!!!" << std::endl
<< "You Win!!!!!" << std::endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac1/扫雷/练习/066 copy.cpp
|
C++
|
unknown
| 5,712
|
#include <iostream>
using namespace std;
/*
当前定义了一个结构体类型,数据类型名称为 Data 类型。
*/
struct Data
{
// 数据相关内容,【成员变量】Field
string key;
int value;
// 操作相关,针对于成员变量数据操作,或者针对于当前类型操作 【成员函数】Function
void show()
{
// 结构体中的成员函数可以直接使用结构体内部【成员变量】
cout << "Key : " << key << ", Value : " << value << endl;
}
};
int main(int argc, char const *argv[])
{
// 定义了一个结构体变量
Data data;
/*
结构体内部的所有成员变量和成员函数,都需要结构体变量进行操作
. 是一个运算符,简单理解对应的含义【的】
*/
data.key = "丝绒拿铁";
data.value = 10;
data.show();
cout << "---------------------------" << endl;
Data data2;
data2.key = "红兜兜擀面皮";
data2.value = 8;
data2.show();
return 0;
}
|
2201_76097352/learning-records
|
ac1/结构体/01-结构体基本案例.cpp
|
C++
|
unknown
| 1,037
|
#include <iostream>
using namespace std;
struct Data
{
string key;
int value;
void show()
{
cout << "key : " << key << ", value : "<< value << endl;
}
};
int main(int argc, char const *argv[])
{
Data data;
data.key = " 丝绒拿铁";
data.value = 10;
data.show();
Data data2;
data2.key = "qwer";
data2.value = 9;
data2.show();
return 0;
}
|
2201_76097352/learning-records
|
ac1/结构体/011_结构体.cpp
|
C++
|
unknown
| 412
|
#include <iostream>
using namespace std;
struct Student
{
int id;
string name;
int age;
char gender;
void show()
{
cout << "ID : " << id
<< ", Name : " << name
<< ", Age : " << age
<< ", Gender : " << gender << endl;
}
};
/*
当前代码中结构体如果作为函数的参数,请严格遵守以下格式
(Student &stu),实际参数对应结构体变量
*/
void assign_student(Student &stu);
int main(int argc, char const *argv[])
{
/*
使用大括号对当前 Student 结构体变量进行赋值操作
提供的数据必须满足结构体成员变量声明要求。同时
顺序复合当前 Student 结构体成员变量顺序。
*/
Student stu = {1, "磊哥", 16, 'M'};
stu.show();
/*
实际参数就是对应的结构体变量
*/
assign_student(stu);
stu.show();
return 0;
}
void assign_student(Student &stu)
{
stu.id = 20;
stu.name = "臀哥";
}
|
2201_76097352/learning-records
|
ac1/结构体/02-结构体作为函数参数的案例.cpp
|
C++
|
unknown
| 1,001
|
#include <iostream>
using namespace std;
// 默认容量为 10
#define DEFAULT_CAPACITY 10
/*
将数组操作相关数据封装到一个结构体中
包括数组本身 array_data
数组对应容量 capacity
数组存储的有效元素个数 size
*/
struct My_Array
{
/**
* array_data 直接当做 int 类型数组使用。
*/
int *array_data;
/**
* 当前 array_data 数组的容量
*/
int capacity;
/**
* 当前 array_data 数组的有效元素个数
*/
int size;
/*
需要在 My_Array 结构体中,实现【增删改查】内容。将之前讲解的
数组相关算法移植到结构体中,利用结构体成员变量的数据多元性,
更好完成相关代码实现。
*/
/**
* 利用函数对当前结构体中的成员变量进行必要的初始化操作
* 【核心内容】
* 1. 数组相关内存空间申请,临时利用 new 关键字
* 2. 数组容量初始化操作
* 3. 数组有效元素初始化操作
*/
void init_my_array();
/**
* 添加元素到 My_Array 底层 array_data 数组中,采用的添加
* 方式为尾插法。
*
* @param ele 用户提供的 int 类型元素
*/
void add_element(int ele);
/**
* 展示底层数组的数据相关内容
*/
void show();
};
int main(int argc, char const *argv[])
{
My_Array my_array;
// my_array 调用初始化操作
my_array.init_my_array();
my_array.add_element(1);
my_array.add_element(2);
my_array.add_element(3);
my_array.show();
return 0;
}
/*
My_Array::init_my_array
My_Array:: 作用域运算符, 俗称 四饼
明确告知编译器,当前实现的函数是 My_Array 结构体中的
成员函数。
*/
void My_Array::init_my_array()
{
/*
申请存储 int 类型数据的数组空间
*/
array_data = new int[DEFAULT_CAPACITY];
/*
capacity 对应底层数组的容量,赋值为默认容量 DEFAULT_CAPACITY
*/
capacity = DEFAULT_CAPACITY;
/*
当前 size 有效元素个数为 0
*/
size = 0;
}
void My_Array::add_element(int ele)
{
array_data[size++] = ele;
}
void My_Array::show()
{
// 当前数组有效元素为 0 ,没有元素
if (0 == size)
{
cout << "[]" << endl;
}
cout << '[';
for (int i = 0; i < size - 1; i++)
{
cout << array_data[i] << ", ";
}
cout << array_data[size - 1] << ']' << endl;
}
|
2201_76097352/learning-records
|
ac1/结构体/03-自定义数组工具箱.cpp
|
C++
|
unknown
| 2,545
|
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
struct A
{
string name;
int age;
string hobby;
int arry[10];
};
int main(int argc, char const *argv[])
{
A a;
a.name = "abc";
a.age = 1;
a.hobby = "qwer";
int new_arry[] = {1, 2, 3, 4, 5, 6, 0, 0 ,0, 0};
for (int i = 0; i < 10; i++)
{
a.arry[i] = new_arry[i];
}
cout << a.name << a.age << a.hobby <<endl;
for (int i = 0; i < 10; i++)
{
cout << a.arry[i] ;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/作业/03_结构体练习.cpp
|
C++
|
unknown
| 557
|
#include <iostream>
#include "my_array.h"
using namespace std;
int main(int argc, char const *argv[])
{
My_Array my_array;
My_Array ma;
// my_array 调用初始化操作
my_array.init_my_array();
my_array.add_element(1);
my_array.add_element(3);
my_array.add_element(1);
my_array.add_element(7);
my_array.add_element(1);
my_array.add_element(3);
my_array.show();
cout << "max_value : " << my_array.max_value() << endl;
cout << "min_value : " << my_array.min_value() << endl;
cout << "avg_value : " << my_array.avg_value() << endl;
cout << "元素 1 第一次出现的下标位置:" << my_array.find(1) << endl;
cout << "元素 1 最后一次出现的下标位置:" << my_array.rfind(1) << endl;
cout << "----------01---------" <<endl;
//添加指定元素到指定下标位置
my_array.add_element(6,9);
cout << "添加元素到指定下标位置后的数组:" ;
my_array.show();
cout << "----------02---------" <<endl;
//删除指定下标元素
int ret = my_array.remove(1);
if(0 == ret)
{
cout << "当前下标位置大于数组最大下标位置~~~" << endl;
}
else
{
cout << "被删除的元素为:" << ret << endl;
}
cout << "删除指定下标元素后的数组为:";
my_array.show();
cout << "----------03---------" <<endl;
//删除所有指定目标元素
my_array.remove_all(1);
cout << "删除所有 1 元素后的数组为:";
my_array.show();
cout << "qnwedlifabvpaweirvhapou" <<endl;
my_array.add_element(1);
my_array.add_element(9);
my_array.add_element(4);
my_array.add_element(2);
// add_all( ma);
my_array.remove(4);
cout << "----------04---------" <<endl;
my_array.show();
cout << "---------05---------" <<endl;
cout << "----------06---------" <<endl;
my_array.remove_all(90);
cout << "----------07---------" <<endl;
my_array.show();
my_array.remove_all(2,5);
cout << "----------08---------" <<endl;
my_array.show();
my_array.replace(2,1333);
cout << "----------09---------" <<endl;
my_array.show();
my_array.replace_all(1333,321);
cout << "----------10---------" <<endl;
my_array.show();
my_array.reveser();
cout << "----------11---------" <<endl;
my_array.show();
cout << "----------12---------" << endl << my_array.at(7) << endl;
my_array.sort_desc();
cout << "----------13---------" <<endl;
my_array.show();
my_array.sort_asc();
cout << "----------14---------" <<endl;
my_array.show();
return 0;
}
|
2201_76097352/learning-records
|
ac2/作业/作业1/04-多文件效果.cpp
|
C++
|
unknown
| 2,680
|
#include "my_array.h"
using namespace std;
/*
My_Array::init_my_array
My_Array:: 作用域运算符, 俗称 四饼
明确告知编译器,当前实现的函数是 My_Array 结构体中的
成员函数。
*/
void My_Array::init_my_array()
{
/*
申请存储 int 类型数据的数组空间
*/
array_data = new int[DEFAULT_CAPACITY];
memset(array_data, 0, DEFAULT_CAPACITY);
/*
capacity 对应底层数组的容量,赋值为默认容量 DEFAULT_CAPACITY
*/
capacity = DEFAULT_CAPACITY;
/*
当前 size 有效元素个数为 0
*/
size = 0;
}
void My_Array::add_element(int ele)
{
array_data[size++] = ele;
}
void My_Array::show()
{
// 当前数组有效元素为 0 ,没有元素
if (0 == size)
{
cout << "[]" << endl;
}
cout << '[';
for (int i = 0; i < size - 1; i++)
{
cout << array_data[i] << ", ";
}
cout << array_data[size - 1] << ']' << endl;
}
int My_Array::min_value()
{
/*
结构体中的成员函数可以直接使用结构体内部的成员变量
array_data 结构体中的数据数组
size 是当前数组的有效元素个数
*/
int min_value = array_data[0];
for (int i = 1; i < size; i++)
{
if (array_data[i] < min_value)
{
min_value = array_data[i];
}
}
return min_value;
}
int My_Array::max_value()
{
/*
结构体中的成员函数可以直接使用结构体内部的成员变量
array_data 结构体中的数据数组
size 是当前数组的有效元素个数
*/
int max_value = array_data[0];
for (int i = 1; i < size; i++)
{
if (array_data[i] > max_value)
{
max_value = array_data[i];
}
}
return max_value;
}
double My_Array::avg_value()
{
int total_value = 0;
for (int i = 0; i < size; i++)
{
total_value += array_data[i];
}
return total_value / (size * 1.0);
}
int My_Array ::find(int value)
{
for(int i = 0; i < size; i++)
{
if(array_data[i] == value)
{
return i;
}
}
return -1;
}
int My_Array ::rfind(int value)
{
int index = -1;
for(int i = 0; i < size; i++)
{
if(array_data[i] == value)
{
index = i;
}
}
return index;
}
void My_Array ::add_element(int index, int ele)
{
if(index > size || index < 0)
{
cout << "该位置不能添加元素" << endl;
}
else
{
array_data[size++] = ele;
for(int i = size; i >= index; i--)
{
array_data[i] = array_data[i - 1];
}
array_data[index] = ele;
}
}
void My_Array::add_all(My_Array &ma)
{
// 检查是否需要扩容
if (size + ma.size > capacity)
{
// 扩容逻辑
int new_capacity = capacity + ma.size;
int *new_array = new int[new_capacity];
memcpy(new_array, array_data, size * sizeof(int));
delete[] array_data;
array_data = new_array;
capacity = new_capacity;
}
// 将 ma 的元素添加到当前数组末尾
for (int i = 0; i < ma.size; i++)
{
array_data[size++] = ma.array_data[i];
}
for (int i = 0; i < ma.size; i++)
{
cout << array_data[i] << " " ;
}
}
void My_Array::add_all(int index, My_Array &ma)
{
if (index < 0 || index > size)
{
cout << "下标越界,无法添加元素" << endl;
return;
}
// 检查是否需要扩容
if (size + ma.size > capacity)
{
// 扩容逻辑
int new_capacity = capacity + ma.size;
int *new_array = new int[new_capacity];
memcpy(new_array, array_data, size * sizeof(int));
delete[] array_data;
array_data = new_array;
capacity = new_capacity;
}
// 将原数组从 index 开始的元素向后移动 ma.size 个位置
for (int i = size - 1; i >= index; i--)
{
array_data[i + ma.size] = array_data[i];
}
// 将 ma 的元素插入到 index 位置
for (int i = 0; i < ma.size; i++)
{
array_data[index + i] = ma.array_data[i];
}
size += ma.size;
}
int My_Array::remove(int index)
{
int ret = array_data[index];
if(index >= size)
{
return 0;
}
else
{
for(int i = index; i < size - 1; i++)
{
array_data[i] = array_data[i + 1];
}
size -= 1;
return ret;
}
}
void My_Array::remove_all(int ele)
{
int count = 0;
for(int i = 0; i < size; i++)
{
if(array_data[i] == ele)
{
for(int j = i; j < size; j++)
{
array_data[j] = array_data[j + 1];
}
i--;
count++;
}
}
size -= count;
}
void My_Array::remove_all(My_Array &ma)
{
// 遍历 ma 中的元素,逐个删除
for (int i = 0; i < ma.size; i++)
{
remove_all(ma.array_data[i]);
}
}
void My_Array::retain_all(My_Array &ma)
{
// 创建一个临时数组,用于存储交集
int *temp_array = new int[size];
int temp_size = 0;
// 遍历当前数组,检查元素是否在 ma 中
for (int i = 0; i < size; i++)
{
if (ma.find(array_data[i]) != -1)
{
temp_array[temp_size++] = array_data[i];
}
}
// 释放原数组内存,替换为临时数组
delete[] array_data;
array_data = temp_array;
size = temp_size;
}
void My_Array::remove_all(int begin, int end)
{
int count = 0;
if(begin >= end || begin < 0 || begin > size - 1)
{
cout << "您输入的初始或终止下标不合法~~~" << endl;
}
for(int i = begin; i < (size > begin ? begin : size); i++)
{
array_data[i] = 0;
if(0 == array_data[i])
{
for(int j = i; j < size; j++)
{
array_data[j] = array_data[j + 1];
}
i--;
count++;
}
}
size -=count;
}
void My_Array::destroy()
{
delete[] array_data;
}
void My_Array::replace(int index, int new_value)
{
if (index < 0 || index >= size)
{
cout << "下标越界,无法替换元素" << endl;
return;
}
array_data[index] = new_value;
}
void My_Array::replace_all(int old_value, int new_value)
{
for (int i = 0; i < size; i++)
{
if (array_data[i] == old_value)
{
array_data[i] = new_value;
}
}
}
void My_Array::replace_all(int pos, int count, My_Array &ma)
{
if (pos < 0 || pos >= size || count < 0 || pos + count > size)
{
cout << "参数不合法,无法替换元素" << endl;
return;
}
// 检查是否需要扩容
if (size - count + ma.size > capacity)
{
// 扩容逻辑
int new_capacity = size - count + ma.size;
int *new_array = new int[new_capacity];
memcpy(new_array, array_data, size * sizeof(int));
delete[] array_data;
array_data = new_array;
capacity = new_capacity;
}
// 将原数组从 pos + count 开始的元素向后移动 ma.size - count 个位置
for (int i = size - 1; i >= pos + count; i--)
{
array_data[i + ma.size - count] = array_data[i];
}
// 将 ma 的元素插入到 pos 位置
for (int i = 0; i < ma.size; i++)
{
array_data[pos + i] = ma.array_data[i];
}
size = size - count + ma.size;
}
void My_Array::reveser()
{
for (int i = 0; i < size / 2; i++)
{
int temp = array_data[i];
array_data[i] = array_data[size - 1 - i];
array_data[size - 1 - i] = temp;
}
}
int My_Array::at(int index)
{
if (index < 0 || index >= size)
{
cout << "下标越界,无法获取元素" << endl;
return -1; // 返回 -1 表示错误
}
return array_data[index];
}
My_Array &My_Array::sub_array(int pos, int count)
{
if (pos < 0 || pos >= size || count < 0 || pos + count > size)
{
cout << "参数不合法,无法获取子数组" << endl;
return *this; // 返回当前对象
}
// 创建新的 My_Array 对象
My_Array *sub = new My_Array();
sub->init_my_array();
// 复制子数组内容
for (int i = pos; i < pos + count; i++)
{
sub->add_element(array_data[i]);
}
return *sub;
}
void My_Array::sort_desc()
{
// 降序排序
for (int i = 0; i < size - 1; i++)
{
for (int j = 0; j < size - 1 - i; j++)
{
if (array_data[j] < array_data[j + 1])
{
int temp = array_data[j];
array_data[j] = array_data[j + 1];
array_data[j + 1] = temp;
}
}
}
}
void My_Array::sort_asc()
{
// 升序排序
for (int i = 0; i < size - 1; i++)
{
for (int j = 0; j < size - 1 - i; j++)
{
if (array_data[j] > array_data[j + 1])
{
int temp = array_data[j];
array_data[j] = array_data[j + 1];
array_data[j + 1] = temp;
}
}
}
}
|
2201_76097352/learning-records
|
ac2/作业/作业1/my_array.cpp
|
C++
|
unknown
| 9,198
|
#ifndef _MY_ARRAY_
#define _MY_ARRAY_
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
// 默认容量为 10
#define DEFAULT_CAPACITY 10
/*
将数组操作相关数据封装到一个结构体中
包括数组本身 array_data
数组对应容量 capacity
数组存储的有效元素个数 size
*/
struct My_Array
{
/**
* array_data 直接当做 int 类型数组使用。
*/
int *array_data;
/**
* 当前 array_data 数组的容量
*/
int capacity;
/**
* 当前 array_data 数组的有效元素个数
*/
int size;
/*
需要在 My_Array 结构体中,实现【增删改查】内容。将之前讲解的
数组相关算法移植到结构体中,利用结构体成员变量的数据多元性,
更好完成相关代码实现。
*/
/**
* 利用函数对当前结构体中的成员变量进行必要的初始化操作
* 【核心内容】
* 1. 数组相关内存空间申请,临时利用 new 关键字
* 2. 数组容量初始化操作
* 3. 数组有效元素初始化操作
*/
// ===================================================
void init_my_array();
/**
* 添加元素到 My_Array 底层 array_data 数组中,采用的添加
* 方式为尾插法。
*
* @param ele 用户提供的 int 类型元素
*/
void add_element(int ele);
/**
* 找出当前数组中最大值
*
* @return int 类型数组中存储的最大值
*/
int min_value();
/**
* 找出当前数组中的最小值
*
* @return int 类型数组中存储的最小值
*/
int max_value();
/**
* 返回整个数组数据的平均值
*
* @return double 类型数组中存储的平均值
*/
double avg_value();
/**
* 展示底层数组的数据相关内容
*/
void show();
/**
* 找出指定数据在底层数组中第一次出现的下标位置
*
* @param value 目标搜索的数据
* @return 数据在底层数组中第一次出现的下标位置,如果找到
* 返回大于等于 0,否则返回 -1
*/
int find(int value);
/**
* 找出指定数据在底层数组中最后一次出现的下标位置
*
* @param value 目标搜索的数据
* @return 数据在底层数组中最后一次出现的下标位置,如果找到
* 返回大于等于 0,否则返回 -1
*/
int rfind(int value);
/**
* 在当前底层数组中,添加指定元素到目标指定下标
*
* @param index 指定添加数据的下标位置。
* @param ele 指定添加的元素
*/
void add_element(int index, int ele);
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组末尾。
*
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
void add_all(My_Array &ma);
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组指定下标位置 index
*
* @param index 指定添加另一个数组的下标位置
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
void add_all(int index, My_Array &ma);
/**
* 删除当前 My_Array 中指定下标的元素,返回值是被删除的元素数据情况
*
* @param index 指定删除数据的下标位置
* @return int 对应当前被删除的数据情况
*/
int remove(int index);
/**
* 在当前 My_Array 中删除所有的目标 ele 元素
*
* @param ele 目标删除的元素数据
*/
void remove_all(int ele);
/**
* 在当前 My_Array 中删除和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [1, 1, 6]
*
* @param ma 删除依据的参数 My_Array 结构体
*/
void remove_all(My_Array &ma);
/**
* 在当前 My_Array 中,删除底层数组中存储的从 begin 开始到 end 下标结束的
* 所有数据数据内容,要求要头不要尾 [begin, end)
*
* @param begin 删除数据的起始下标位置
* @param end 删除数据的终止下标位置
*/
void remove_all(int begin, int end);
/**
* 在当前 My_Array 中仅保留和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [3, 5, 3, 5]
*
* @param ma 保留数据依据的参数 My_Array 结构体
*/
void retain_all(My_Array &ma);
/**
* 在当前 My_Array 底层数组中,指定下标位置 index 替换为新元素
*
* @param index 替换指定的下标位置
* @param new_value 替换使用的新元素
*/
void replace(int index, int new_value);
/**
* 将当前 My_Array 底层数组中所有的 old_value 替换为 new_value
*
* @param old_value 替换目标的老数据
* @param new_value 替换使用的新数据
*/
void replace_all(int old_value, int new_value);
/**
* 在当前 My_Array 底层数组中,从指定下标为 pos 开始,计数 count 元素
* 替换为参数 My_Array 对应的数据
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 参数 My_Array 底层数据 [9, 8, 7]
* 其他参数实际数据为 pos = 2, count = 2;
* 执行效果为当前调用函数 My_Array 底层数据
* [1, 2, 9, 8, 7, 5];
*
* @param pos 指定替换数据的起始下标位置
* @param count 替换数据的个数
* @param ma 替换数据的新数据 My_Array
*/
void replace_all(int pos, int count, My_Array &ma);
/**
* 当前 My_Array 底层数组逆序操作
*/
void reveser();
/**
* 在当前 My_Array 中,找出用户指定下标 index 对应的元素
*
* @param 返回值是目标元素
*/
int at(int index);
/**
* 在当前调用函数的 My_Array 中,从指定下标位置 pos 开始,计数 count 个数
* 截取得到子 My_Array 结构体
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 其他参数实际数据为 pos = 2, count = 2;
* 得到的新 My_Array,底层数据为 [2, 3]
*
* @param pos 截取子 My_Array 指定的起始下标位置
* @param count 截取操作对应的元素个数
* @return 对应当前 My_Array 限制范围以内的子 My_Array 结构体数据
*/
My_Array &sub_array(int pos, int count);
/**
* My_Array 底层数据降序排序,临时排序展示操作,对原数据内容无影响
*/
void sort_desc();
/**
* My_Array 底层数据升序排序,临时排序展示操作,对原数据内容无影响
*/
void sort_asc();
/**
* 销毁当前 My_Array 占用的内存空间
*/
void destroy();
};
#endif
|
2201_76097352/learning-records
|
ac2/作业/作业1/my_array.h
|
C++
|
unknown
| 7,478
|
init_my_array()
add_element(int ele)
min_value()
max_value()
avg_value()
show()
find(int value)
rfind(int value)
/**
* 在当前底层数组中,添加指定元素到目标指定下标
*
* @param index 指定添加数据的下标位置。
* @param ele 指定添加的元素
*/
add_element(int index, int ele)
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组末尾。
*
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
add_all(My_Array &ma)
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组指定下标位置 index
*
* @param index 指定添加另一个数组的下标位置
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
add_all(int index, My_Array &ma)
/**
* 删除当前 My_Array 中指定下标的元素,返回值是被删除的元素数据情况
*
* @param index 指定删除数据的下标位置
* @return int 对应当前被删除的数据情况
*/
remove(int index)
/**
* 在当前 My_Array 中删除所有的目标 ele 元素
*
* @param ele 目标删除的元素数据
*/
remove_all(int ele)
/**
* 在当前 My_Array 中删除和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [1, 1, 6]
*
* @param ma 删除依据的参数 My_Array 结构体
*/
remove_all(My_Array &ma)
/**
* 在当前 My_Array 中,删除底层数组中存储的从 begin 开始到 end 下标结束的
* 所有数据数据内容,要求要头不要尾 [begin, end)
*
* @param begin 删除数据的起始下标位置
* @param end 删除数据的终止下标位置
*/
remove_all(int begin, int end)
/**
* 在当前 My_Array 中仅保留和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [3, 5, 3, 5]
*
* @param ma 保留数据依据的参数 My_Array 结构体
*/
retain_all(My_Array &ma)
/**
* 在当前 My_Array 底层数组中,指定下标位置 index 替换为新元素
*
* @param index 替换指定的下标位置
* @param new_value 替换使用的新元素
*/
replace(int index, int new_value)
/**
* 将当前 My_Array 底层数组中所有的 old_value 替换为 new_value
*
* @param old_value 替换目标的老数据
* @param new_value 替换使用的新数据
*/
replace_all(int old_value, int new_value)
/**
* 在当前 My_Array 底层数组中,从指定下标为 pos 开始,计数 count 元素
* 替换为参数 My_Array 对应的数据
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 参数 My_Array 底层数据 [9, 8, 7]
* 其他参数实际数据为 pos = 2, count = 2;
* 执行效果为当前调用函数 My_Array 底层数据
* [1, 2, 9, 8, 7, 5];
*
* @param pos 指定替换数据的起始下标位置
* @param count 替换数据的个数
* @param ma 替换数据的新数据 My_Array
*/
replace_all(int pos, int count, My_Array &ma)
/**
* 当前 My_Array 底层数组逆序操作
*/
reveser()
/**
* 在当前 My_Array 中,找出用户指定下标 index 对应的元素
*
* @param 返回值是目标元素
*/
at(int index)
/**
* 在当前调用函数的 My_Array 中,从指定下标位置 pos 开始,计数 count 个数
* 截取得到子 My_Array 结构体
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 其他参数实际数据为 pos = 2, count = 2;
* 得到的新 My_Array,底层数据为 [2, 3]
*
* @param pos 截取子 My_Array 指定的起始下标位置
* @param count 截取操作对应的元素个数
* @return 对应当前 My_Array 限制范围以内的子 My_Array 结构体数据
*/
My_Array &sub_array(int pos, int count)
/**
* My_Array 底层数据降序排序,临时排序展示操作,对原数据内容无影响
*/
sort_desc()
/**
* My_Array 底层数据升序排序,临时排序展示操作,对原数据内容无影响
*/
sort_asc()
/**
* 销毁当前 My_Array 占用的内存空间
*/
destroy()
|
2201_76097352/learning-records
|
ac2/作业/作业1/临时存储.cpp
|
C++
|
unknown
| 4,975
|
#include "homework.h"
#include <iostream>
using namespace std;
void My_Array::init_my_array()
{
/*
申请存储 int 类型数据的数组空间
*/
array_data = new int[DEFAULT_CAPACITY];
memset(array_data, 0, DEFAULT_CAPACITY);
/*
capacity 对应底层数组的容量,赋值为默认容量 DEFAULT_CAPACITY
*/
capacity = DEFAULT_CAPACITY;
/*
当前 size 有效元素个数为 0
*/
size = 0;
}
void My_Array::add_element(int ele)
{
array_data[size++] = ele;
}
void My_Array::show()
{
// 当前数组有效元素为 0 ,没有元素
if (0 == size)
{
cout << "[]" << endl;
}
cout << '[';
for (int i = 0; i < size - 1; i++)
{
cout << array_data[i] << ", ";
}
cout << array_data[ size - 1] << ']' << endl;
}
int My_Array::min_value()
{
/*
结构体中的成员函数可以直接使用结构体内部的成员变量
array_data 结构体中的数据数组
size 是当前数组的有效元素个数
*/
int min_value = array_data[0];
for (int i = 1; i < size; i++)
{
if (array_data[i] < min_value)
{
min_value = array_data[i];
}
}
return min_value;
}
int My_Array::max_value()
{
/*
结构体中的成员函数可以直接使用结构体内部的成员变量
array_data 结构体中的数据数组
size 是当前数组的有效元素个数
*/
int max_value = array_data[0];
for (int i = 1; i < size; i++)
{
if (array_data[i] > max_value)
{
max_value = array_data[i];
}
}
return max_value;
}
double My_Array::avg_value()
{
int total_value = 0;
for (int i = 0; i < size; i++)
{
total_value += array_data[i];
}
return total_value / (size * 1.0);
}
int My_Array::find(int value)
{
int index = -1;
for (int i = 0; i <= size; i++)
{
if (array_data[i] == value)
{
index = i;
break;
}
}
return index;
}
int My_Array::rfind(int value)
{
int index = -1;
for (int i = size - 1; i >= 0; i--)
{
if (array_data[i] == value)
{
index = i;
break;
}
}
return index;
}
void My_Array::add_element(int index, int ele)
{
int temp = 0;
temp = array_data[index];
for (int i = size - 1; i > index; i--)
{
array_data[i] = array_data[i - 1];
}
array_data[index] = ele;
}
int My_Array::remove(int index)
{
int temp = array_data[index];
for (int i = index; i < size - 1; i++)
{
array_data[i] = array_data[i + 1];
}
size--;
return temp;
}
void My_Array::remove_all(int ele)
{
int num = 0;
for (int i = 0; i < size; i++)
{
if (ele != array_data[i])
{
array_data[num++] = array_data[i];
}
}
size = num;
}
void My_Array::remove_all(int begin, int end)
{
while (begin >= 0 && end <= size)
{
array_data[begin + 1] = array_data[end + 1];
begin++;
end++;
}
size -= (end - begin);
}
void My_Array::replace(int index, int new_value)
{
array_data[index] = new_value;
}
void My_Array::replace_all(int old_value, int new_value)
{
for (int i = 0; i < size; i++)
{
if (old_value == array_data[i])
{
array_data[i] = new_value;
}
}
}
void My_Array::reveser()
{
int temp = 0;
for (int i = 0; i < size / 2; i++)
{
temp = array_data[i];
array_data[i] = array_data[size - i - 1];
array_data[size - i - 1] = temp;
}
}
int My_Array::at(int index)
{
return array_data[index];
}
void My_Array::sort_desc()
{
for (int i = 0; i < size;i++)
{
int max = array_data[i];
for (int j = i + 1; j < size; j++)
{
if (array_data[j] >= max)
{
max = array_data[j];
array_data[j] = array_data[i];
array_data[i] = max;
}
}
}
}
void My_Array::sort_asc()
{
for (int i = 0; i < size;i++)
{
int min = array_data[i];
for (int j = i + 1; j < size; j++)
{
if (array_data[j] <= min)
{
min = array_data[j];
array_data[j] = array_data[i];
array_data[i] = min;
}
}
}
}
void My_Array::add_all(My_Array &ma)
{
for (int i = 0; i < ma.size; i++)
{
array_data[i + size] = ma.array_data[i];
}
size += ma.size;
}
void My_Array::add_all(int index, My_Array &ma)
{
if (index >= 0 && index <= size)
{
for (int j = index + ma.size; j < capacity; j++)
{
array_data[j] = array_data[j - ma.size];
}
for (int i = 0; i < ma.size; i++)
{
array_data[i + index] = ma.array_data[i];
}
size += ma.size;
}
else
{
cout << "越界了 !" << endl;
}
}
void My_Array::remove_all(My_Array &ma)
{
int num = size;
for (int i = 0; i < ma.size; i++)
{
for (int j = 0; j < size; j++)
{
if (array_data[j] == ma.array_data[i])
{
for (int k = j; k < size;k++)
{
array_data[k] = array_data[k + 1];
}
num--;
break;
}
}
}
size = num;
}
void My_Array::retain_all(My_Array &ma)
{
int num = size;
int status = 1;
for (int i = 0; i < num; i++)
{
status = 1;
for (int j = 0; j < ma.size; j++)
{
if (array_data[i] == ma.array_data[j])
{
status = 0;
break;
}
}
if (status)
{
for (int k = i; k < num - 1;k++)
{
array_data[k] = array_data[k + 1];
}
num--;
i--;
}
}
size = num;
}
void My_Array::replace_all(int pos, int count, My_Array &ma)
{
if (pos + count > size)
{
cout << "越界了哥们儿 !!" << endl;
}
else
{
for (int i = pos; i <= count; i++)
{
array_data[pos + i] = ma.array_data[i];
}
}
}
My_Array &My_Array::sub_array(int pos, int count)
{
// 创建一个新的 My_Array 对象
My_Array *result = new My_Array();
// 检查 pos 和 count 的合法性
if (pos < 0 || pos >= size || count <= 0)
{
// 如果参数不合法,返回一个空的 My_Array
result->size = 0;
result->array_data = nullptr;
return *result;
}
// 计算实际可以截取的元素个数
int actual_count = (pos + count > size) ? (size - pos) : count;
// 为新数组分配内存
result->array_data = new int[actual_count];
result->size = actual_count;
// 复制数据到新数组
for (int i = 0; i < actual_count; i++)
{
result->array_data[i] = array_data[pos + i];
}
// 返回新数组
return *result;
}
void My_Array::destroy()
{
delete[] array_data;
}
|
2201_76097352/learning-records
|
ac2/作业/作业2/homework.cpp
|
C++
|
unknown
| 7,267
|
#ifndef _HOMEWORK_
#define _HOMEWORK_
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
// 默认容量为 10
#define DEFAULT_CAPACITY 10
/*
将数组操作相关数据封装到一个结构体中
包括数组本身 array_data
数组对应容量 capacity
数组存储的有效元素个数 size
*/
struct My_Array
{
/**
* array_data 直接当做 int 类型数组使用。
*/
int *array_data;
/**
* 当前 array_data 数组的容量
*/
int capacity;
/**
* 当前 array_data 数组的有效元素个数
*/
int size;
/*
需要在 My_Array 结构体中,实现【增删改查】内容。将之前讲解的
数组相关算法移植到结构体中,利用结构体成员变量的数据多元性,
更好完成相关代码实现。
*/
/**
* 利用函数对当前结构体中的成员变量进行必要的初始化操作
* 【核心内容】
* 1. 数组相关内存空间申请,临时利用 new 关键字
* 2. 数组容量初始化操作
* 3. 数组有效元素初始化操作
*/
void init_my_array();
/**
* 添加元素到 My_Array 底层 array_data 数组中,采用的添加
* 方式为尾插法。
*
* @param ele 用户提供的 int 类型元素
*/
void add_element(int ele);
/**
* 找出当前数组中最大值
*
* @return int 类型数组中存储的最大值
*/
int min_value();
/**..
* 找出当前数组中的最小值
*
* @return int 类型数组中存储的最小值
*/
int max_value();
/**
* 返回整个数组数据的平均值
*
* @return double 类型数组中存储的平均值
*/
double avg_value();
/**
* 展示底层数组的数据相关内容
*/
void show();
/**
* 找出指定数据在底层数组中第一次出现的下标位置
*
* @param value 目标搜索的数据
* @return 数据在底层数组中第一次出现的下标位置,如果找到
* 返回大于等于 0,否则返回 -1
*/
int find(int value);
/**
* 找出指定数据在底层数组中最后一次出现的下标位置
*
* @param value 目标搜索的数据
* @return 数据在底层数组中最后一次出现的下标位置,如果找到
* 返回大于等于 0,否则返回 -1
*/
int rfind(int value);
/**
* 在当前底层数组中,添加指定元素到目标指定下标
*
* @param index 指定添加数据的下标位置。
* @param ele 指定添加的元素
*/
void add_element(int index, int ele);
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组末尾。
*
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
void add_all(My_Array &ma);
/**
* 添加另一个 My_Array 结构体变量数据到当前 My_Array 中
* 主要是将参数的 My_Array 底层数组内容拷贝到当前 My_Array
* 底层数组指定下标位置 index
*
* @param index 指定添加另一个数组的下标位置
* @param ma 添加到当前 My_Array 底层数组的结构体 My_Array 变量
*/
void add_all(int index, My_Array &ma);
/**
* 删除当前 My_Array 中指定下标的元素,返回值是被删除的元素数据情况
*
* @param index 指定删除数据的下标位置
* @return int 对应当前被删除的数据情况
*/
int remove(int index);
/**
* 在当前 My_Array 中删除所有的目标 ele 元素
*
* @param ele 目标删除的元素数据
*/
void remove_all(int ele);
/**
* 在当前 My_Array 中删除和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [1, 1, 6]
*
* @param ma 删除依据的参数 My_Array 结构体
*/
void remove_all(My_Array &ma);
/**
* 在当前 My_Array 中,删除底层数组中存储的从 begin 开始到 end 下标结束的
* 所有数据数据内容,要求要头不要尾 [begin, end)
*
* @param begin 删除数据的起始下标位置
* @param end 删除数据的终止下标位置
*/
void remove_all(int begin, int end);
/**
* 在当前 My_Array 中仅保留和参数 My_Array 的交集
* 例如:
* 当前 My_Array 底层数据为 [1, 3, 5, 1, 3, 5, 6]
* 参数 ma 底层数据为 [3, 5, 2]
* 调用之后的效果为 [3, 5, 3, 5]
*
* @param ma 保留数据依据的参数 My_Array 结构体
*/
void retain_all(My_Array &ma);
/**
* 在当前 My_Array 底层数组中,指定下标位置 index 替换为新元素
*
* @param index 替换指定的下标位置
* @param new_value 替换使用的新元素
*/
void replace(int index, int new_value);
/**
* 将当前 My_Array 底层数组中所有的 old_value 替换为 new_value
*
* @param old_value 替换目标的老数据
* @param new_value 替换使用的新数据
*/
void replace_all(int old_value, int new_value);
/**
* 在当前 My_Array 底层数组中,从指定下标为 pos 开始,计数 count 元素
* 替换为参数 My_Array 对应的数据
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 参数 My_Array 底层数据 [9, 8, 7]
* 其他参数实际数据为 pos = 2, count = 2;
* 执行效果为当前调用函数 My_Array 底层数据
* [1, 2, 9, 8, 7, 5];
*
* @param pos 指定替换数据的起始下标位置
* @param count 替换数据的个数
* @param ma 替换数据的新数据 My_Array
*/
void replace_all(int pos, int count, My_Array &ma);
/**
* 当前 My_Array 底层数组逆序操作
*/
void reveser();
/**
* 在当前 My_Array 中,找出用户指定下标 index 对应的元素
*
* @param 返回值是目标元素
*/
int at(int index);
/**
* 在当前调用函数的 My_Array 中,从指定下标位置 pos 开始,计数 count 个数
* 截取得到子 My_Array 结构体
* 例如
* 当前调用函数 My_Array 底层数据 [1, 2, 3, 4, 5];
* 其他参数实际数据为 pos = 2, count = 2;
* 得到的新 My_Array,底层数据为 [2, 3]
*
* @param pos 截取子 My_Array 指定的起始下标位置
* @param count 截取操作对应的元素个数
* @return 对应当前 My_Array 限制范围以内的子 My_Array 结构体数据
*/
My_Array &sub_array(int pos, int count);
/**
* My_Array 底层数据降序排序,临时排序展示操作,对原数据内容无影响
*/
void sort_desc();
/**
* My_Array 底层数据升序排序,临时排序展示操作,对原数据内容无影响
*/
void sort_asc();
/**
* 销毁当前 My_Array 占用的内存空间
*/
void destroy();
void extend(int capacity);
};
#endif
|
2201_76097352/learning-records
|
ac2/作业/作业2/homework.h
|
C++
|
unknown
| 7,452
|
#include "homework.h"
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
My_Array my_array;
// my_array 调用初始化操作
my_array.init_my_array();
my_array.add_element(11);
my_array.add_element(3);
my_array.add_element(5);
my_array.add_element(777);
my_array.add_element(9);
my_array.add_element(2);
my_array.add_element(4);
my_array.add_element(6);
my_array.add_element(7);
//my_array.add_element(8);
my_array.add_element(10);
cout << "my_array : ";
my_array.show();
My_Array ma;
ma.init_my_array();
ma.add_element(11);
ma.add_element(33);
ma.add_element(55);
ma.add_element(777);
cout << "ma : ";
ma.show();
my_array.replace_all(1, 1, ma);
cout << "after replacing ma at particular pos :";
my_array.show();
my_array.remove_all(ma);
cout << "after removing all the same value with ma :";
my_array.show();
/*
my_array.retain_all(ma);
cout << "only retaining all the same value with ma :";
my_array.show();
*/
cout << "max_value : " << my_array.max_value() << endl;
cout << "min_value : " << my_array.min_value() << endl;
cout << "avg_value : " << my_array.avg_value() << endl;
cout << "where is the first position of the value : " << my_array.find(8) << endl;
cout << "where is the last position of the value : " << my_array.rfind(7) << endl;
my_array.add_element(4,111);
cout << "after adding an ele at particular index :";
my_array.show();
my_array.remove(4);
cout << "after removing an ele at particular index :";
my_array.show();
my_array.remove_all(2);
cout << "after removing all particular ele :";
my_array.show();
my_array.remove_all(2,5);
cout << "after removing all ele from 2 to 5:";
my_array.show();
my_array.replace(2,123);
cout << "after replacing :";
my_array.show();
my_array.replace_all(123,321);
cout << "after replacing all :";
my_array.show();
my_array.reveser();
cout << "after revesering :";
my_array.show();
cout << "the particular index value is :" << my_array.at(7) << endl;
my_array.sort_desc();
cout << "sort in descending order :";
my_array.show();
my_array.sort_asc();
cout << "sort in ascending order :";
my_array.show();
/*
if (my_array.size + ma.size <= my_array.capacity)
{
cout << "after adding ma :";
my_array.add_all(ma);
my_array.show();
}
else
{
cout << "越界了哥们儿 !!" << endl;
}
*/
/*
if (my_array.size + ma.size <= my_array.capacity)
{
cout << "after adding ma at particular index :";
my_array.add_all(2,ma);
my_array.show();
}
else
{
cout << "越界了哥们儿 !!" << endl;
}
*/
return 0;
}
|
2201_76097352/learning-records
|
ac2/作业/作业2/main_homework.cpp
|
C++
|
unknown
| 2,929
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int a = 0;
int b = 0;
cout << "请输入两个数" <<endl;
cin >> a >> b ;
if(a < b)
{
cout << "您输入两个数,其中最大的是:" << b <<endl;
}
else
cout << "您输入两个数,其中最大的是:" << a <<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/01_输入两个整数,输出较大的数(要求用if-else实现).cpp
|
C++
|
unknown
| 376
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int a = 0;
// int b = 0;
cout << "请输入一个数" <<endl;
cin >> a ;
if(a < 0)
{
cout << "您输入的数小于零" << a <<endl;
}
else if(a == 0)
{
cout << "您输入的数为“ 0 "<< a <<endl;
}
else
cout << "您输入的数大于零" << a <<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/02_输入一个整数,判断是正数、负数还是零.cpp
|
C++
|
unknown
| 425
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cout << "输入一个年份"<<endl;
int a = 0;
cin >> a;
if(a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
{
cout << "你输入的年份为闰年"<<endl;
}
else{
cout << "您输入的年份不是闰年"<<endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/04_输入年份,判断是否为闰年(闰年条件:能被4整除但不能被100整除,或能被400整除.cpp
|
C++
|
unknown
| 356
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
// int capaciyt = 3;
int temp = 0;
int arr[3] = {0};
for (int i = 0; i < 3; i++)
{
cout << " 请输入第" << i+1 <<"个数"<<endl;
cin >> arr[i];
}
for (int i = 0; i < 3; i++)
{
cout << arr[i] << " ";
}
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (a[i] < a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
cout <<"三个数从大到小排列为:"<< endl;
for (int i = 0; i < 3; i++)
{
cout << arr[i] << " ";
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/05_输入三个数,按从小到大顺序输出.cpp
|
C++
|
unknown
| 743
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char a = 'a';
cout << "请输入一个字符" <<endl;
cin >> a;
if(a >= 49 && a <= 57)
{
cout << "您输入的字符为数字"<<endl;
}
else if(a >= 65 && a <= 90)
{
cout << "您输入的字符为大写字母"<<endl;
}
else if(a >= 97 && a <= 122)
{
cout <<"您输入的字符为小写字母" <<endl;
}
else
cout <<"您输入的字符为其他字符"<<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/06_输入字符,判断是字母、数字还是其他字符.cpp
|
C++
|
unknown
| 540
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int a[3] = {0};
for (int i = 0; i < 3; i++)
{
cout <<"请输三角形的第 "<< i + 1 << "边长"<<endl;
cin >> a[i];
}
cout <<"输入的三角形的边长分变为 "<<endl;
for (int i = 0; i < 3; i++)
{
cout << a[i] <<" ";
}
cout <<endl;
int temp = 0;
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (a[i] < a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
cout <<"输入的三角形三边从大到小排列为" <<endl;
for (int i = 0; i < 3; i++)
{
cout << a[i] <<" ";
}
cout << endl;
if(a[0] >= a[1] + a[2])
{
cout << "您输入的三角形三边长不合法"<<endl;
}
else if(a[0] * a[0] == a[1] * a[1] + a[2] * a[2])
{
cout << "您输入的三角形为直角三角形"<< endl;
}
else if(a[0] == a[1] &&a[1] == a[2])
{
cout << "您输入的三角形为等边三角形" <<endl;
}
else if(a[1] == a[2] || a[0] == a[1])
{
cout << "您输入的三角形为等腰三角形" <<endl;
}
else
cout << "您输入的三角形为普通三角形" <<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/09_输入三角形的三边长,判断是否能构成三角形,并判断类型(等边、等腰、直角、普通).cpp
|
C++
|
unknown
| 1,384
|
#include <iostream>
using namespace std;
int main() {
double weight; // 包裹重量
double firstWeightRate = 10.0; // 首重费率(10元/kg)
double additionalWeightRate = 5.0; // 续重费率(5元/kg)
double maxCost = 50.0; // 最大费用(50元)
// 输入包裹重量
cout << "请输入包裹的重量(kg):";
cin >> weight;
// 计算费用
double cost = 0.0;
if (weight <= 0)
{
cout << "重量必须大于0!" << endl;
return 0;
} else if (weight <= 1.0)
{
cost = weight * firstWeightRate; // 只计算首重
} else
{
cost = firstWeightRate + (weight - 1.0) * additionalWeightRate;
// 首重 + 续重
}
// 检查总费用是否超过50元
if (cost > maxCost)
{
cost = maxCost;
}
// 输出结果
cout << "快递费用为:" << cost << " 元" << endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/10_kg(总费用不超过50元).cpp
|
C++
|
unknown
| 933
|
#include <iostream>
using namespace std;
int blend = 0;//初始化存储元素
int main(int argc, char const *argv[])
{
for (int i = 1; i <= 100; i++)
{
blend = i + blend;
}
cout << "1 -100 的和为:" << blend<<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/11计算1+2+3+...+100的和(使用for循环).cpp
|
C++
|
unknown
| 266
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int number = 0;//初始化元素
int new_number = 0;
cout <<"用户输入要求阶乘的数" <<endl;
cin >> number;//用户定义元素
new_number = number;
if(number == 0)
{
cout << "您输入数的阶乘为:1" <<endl;
return 0;
}
for (int i = 1; i < number; i++)
{
new_number = new_number * (number - i);
}
cout << "您输入数的阶乘为:" << new_number << endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/12_输入正整数n,计算n!(阶乘).cpp
|
C++
|
unknown
| 542
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int number = 0;//初始化数据
cin >> number;
if(number < 1)
{
cout << "您输入的数字违规" <<endl;
}
else if(2 == number ||3 == number)
{
cout <<"您输入的数是素数,您输入的数为" << number <<endl;
}
else if(number % 2 != 0 && number % 3 != 0 && number % 7 != 0 && number % 5 != 0)
{
cout <<"您输入的数是素数,您输入的数为" << number <<endl;
}
else
cout <<"您输入的数不是素数,您输入的数为" << number <<endl;
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/13_输出100以内的所有素数(质数).cpp
|
C++
|
unknown
| 639
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
cout << i * j << " ";
}
cout << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/14_打印九九乘法表(要求对齐格式).cpp
|
C++
|
unknown
| 264
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int number = 0;
int a = 0;
cout << "用户输入整数" <<endl;
cin >> number;
int new_number = 0;
while(1)
{
new_number = (number % 10);
number = number / 10;
cout << new_number ;
if(number < 10)
{
cout << number ;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/15_输入一个整数,输出它的逆序数(如输入123,输出321).cpp
|
C++
|
unknown
| 480
|
#include <iostream>
using namespace std;
/**
* 找出1000以内的所有完数(完数:等于其因子之和,如6=1+2+3)
*/
int main(int argc, char const *argv[])
{
int num = 0;
for (int i = 1; i < 1000; i++)
{
for (int j = 1; j < i; j++)
{
if (i % j == 0 )
{
num = num + j;
}
}
if (num == i)
{
cout << i << " 为完数"<<endl;
}
num = 0;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/16_找出1000以内的所有完数(完数:等于其因子之和,如6=1+2+3).cpp
|
C++
|
unknown
| 534
|
#include <iostream>
using namespace std;
/**
* 斐波那契数列:输出前20项(1,1,2,3,5,8...)
*/
int main(int argc, char const *argv[])
{
int arry[20] = {1,1,2};
for (int i = 2; i < 20; i++)
{
arry[i] = arry[i - 1] + arry[i - 2];
}
for (int i = 0; i < 20; i++)
{
cout << arry[i] <<" ";
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/17_斐波那契数列:输出前20项(1,1,2,3,5,8...).cpp
|
C++
|
unknown
| 366
|
#include <iostream>
using namespace std;
/**
* 输入一行字符,统计其中字母、空格、数字和其他字符的个数
*/
int main(int argc, char const *argv[])
{
char import = ' ';
char a = ' ';
cout << "请输入"<<endl;
int letter = 0;
int blank = 0;
int figure = 0;
int characters = 0;
while(1)
{
cin >> import;
cout << import <<" ";
cout <<endl;
if(import >= 65 && import <= 90)
{
letter += 1;
}
else if(import >= 97 && import <= 122)
{
letter += 1;
}
else if(a == import)
{
blank += 1;
}
else if(import >= 48 && import <= 57)
{
figure += 1;
}
else
characters += 1;
cout << "字母个数为:"<< letter << endl
<< "空格个数为:" << blank << endl
<< "数字个数为:"<< figure << endl
<< "其他字符个数为:" << characters << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/18_输入一行字符,统计其中字母、空格、数字和其他字符的个数.cpp
|
C++
|
unknown
| 1,079
|
#include <iostream>
using namespace std;
/**
* @brief 获取数字的某一位(从低位开始)
* @param num 目标数字
* @param pos 位置
* @return 对应位置的数字
*/
int getDigitFromLow(int num, int pos)
{
int divisor = 1;
for (int i = 0; i < pos; ++i)
{
divisor *= 10;
}
return (num / divisor) % 10;
}
/**
* @brief 获取数字的某一位(从高位开始)
* @param num 目标数字
* @param totalDigits 总位数
* @param pos 位置
* @return 对应位置的数字
*/
int getDigitFromHigh(int num, int totalDigits, int pos)
{
int divisor = 1;
for (int i = 0; i < totalDigits - pos - 1; ++i)
{
divisor *= 10;
}
return (num / divisor) % 10;
}
int main()
{
int tall = 0;
cout << "请输入值" <<endl;
cin >> tall;
int num = tall;
int digitsCount = 0;
// 计算数字位数
if (num == 0)
{
digitsCount = 1;
}
else
{
while (num != 0)
{
num /= 10;
digitsCount++;
}
}
cout << "输入的数是 " << digitsCount << " 位数" << endl;
// 比较各位数字
int isPalindrome = 1;
for (int i = 0; i < digitsCount / 2; ++i)
{
int lowDigit = getDigitFromLow(tall, i);
int highDigit = getDigitFromHigh(tall, digitsCount, i);
if (lowDigit != highDigit)
{
isPalindrome = 0;
break;
}
}
if (isPalindrome)
{
cout << "您输入的数是回文数" << endl;
}
else
{
cout << "您输入的数不是回文数" << endl;
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/20_回文数.cpp
|
C++
|
unknown
| 1,665
|
#include <iostream>
#include <random>
using namespace std;
int main(int argc, char const *argv[])
{
// 创建一个随机数引擎
std::random_device rd; // 用于获取随机种子
std::mt19937 gen(rd()); // 使用Mersenne Twister算法作为随机数生成器
// 定义一个分布器,生成范围在1到100之间的整数
std::uniform_int_distribution<> dis(1, 100);
// 生成随机数
int random_number = dis(gen);
std::cout << "随机整数: " << random_number << std::endl;
while(1)
{
int a = 0;
cin >> a ;
if (a < random_number)
{
cout << "输入小了" <<endl;
continue;
}
else if(a > random_number)
{
cout << "输入大了" <<endl;
continue;
}
else if(a == random_number)
{
cout << "输入对了" <<endl;
break;
}
}
return 0;
}
|
2201_76097352/learning-records
|
ac2/分支循环练习题/21_随机数生成.cpp
|
C++
|
unknown
| 882
|
#include <iostream>
using namespace std;
/**
* int arr[10] = {1, 21, 5, 7, 9, 21, 4, 6, 8, 0};
* 当前数组中最大值下标为 1
* 需要得到的数据是最大值对应的下标位置,如果代码中有多个最大值,
* 对应的结果为第一个最大值数据
*/
/**
* @param arr 已知数组
* @param num 用来储存最大值的下标位置
* @return 返回最大值下标的值 num
*/
int output_the_subscript (int arr[], int num);
void show_arry(int arr[]);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 21, 5, 7, 500, 221, 4, 6, 8, 0};
int num = 0;
show_arry(arr);
int a = output_the_subscript (arr, num);
cout << "此数组最大值下标位置为" << a <<endl;
return 0;
}
void show_arry(int arr[])
{
cout << "arr = {" ;
for (int i = 0; i < 10; i++)
{
cout << arr[i] << " " ;
}
cout <<"}"<<endl;
}
int output_the_subscript(int arr[], int num)
{
for (int i = 0; i < 10; i++)
{
if(arr[num] < arr[i])
{
num = i ;
}
}
return num;
}
|
2201_76097352/learning-records
|
ac2/数组练习题/01_找出数组中最大值下标位置.cpp
|
C++
|
unknown
| 1,102
|
#include <iostream>
using namespace std;
/**
* int arr[10] = {1, 21, 5, 7, 9, 21, 4, 6, 8, 0};
* 当前数组中最大值下标为 1
* 需要得到的数据是最大值对应的下标位置,如果代码中有多个最大值,
* 对应的结果为第一个最大值数据
*/
/**
* @param arr 已知数组
* @param num 用来储存最小值的下标位置
* @return 返回最小值下标的值 num
*/
int output_the_subscript (int arr[], int num);
void show_arry(int arr[]);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 21, 5, 7, 500, 221, 4, 6, 8, 0};
int num = 0;
show_arry(arr);
int a = output_the_subscript (arr, num);
cout << "此数组最小值下标位置为" << a <<endl;
return 0;
}
void show_arry(int arr[])
{
cout << "arr = {" ;
for (int i = 0; i < 10; i++)
{
cout << arr[i] << " " ;
}
cout <<"}"<<endl;
}
int output_the_subscript(int arr[], int num)
{
for (int i = 1; i < 10; i++)
{
if(arr[num] > arr[i])
{
num = i ;
}
}
return num;
}
|
2201_76097352/learning-records
|
ac2/数组练习题/02_找出数组中最小值下标位置.cpp
|
C++
|
unknown
| 1,102
|
#include <iostream>
using namespace std;
/**
* int arr[10] = {1, 3, 5, 7, 1, 3, 5, 7, 1, 3};
* // 找出目标元素 5 第一次出现的下标位置,对应下标位置 2
* // 找出目标元素 15 第一处出现的下标位置,当前用户指定数据不存在,返回 -1
*/
/**
* @param arr 用户提供数组
* @param num 指定数字第一次出现小标位置
* @param number 指定数字
*
* @return 返回对应下标,若指定数字在数组中不存在,则返回 -1
*/
int output_the_subscript (int arr[], int number, int num);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 1, 3, 5, 7, 1, 3};
int number = 15;
int num = -2;
int a = output_the_subscript(arr, number, num);
if (a != -1)
{
cout << "5 在数组中第一次出现的下标位置为" << a <<endl;
}
else
{
cout << "您输入的数字不在数组中" <<endl;
}
return 0;
}
int output_the_subscript (int arr[], int number, int num)
{
for (int i = 9; i >= 0; i--)
{
if (number == arr[i])
{
num = i;
}
}
if(num == -2)
{
num = -1;
}
return num;
}
|
2201_76097352/learning-records
|
ac2/数组练习题/03_找出指定元素在数组中第一次出现的下标位置.cpp
|
C++
|
unknown
| 1,220
|
#include <iostream>
using namespace std;
/**
* int arr[10] = {1, 3, 5, 7, 1, 3, 5, 7, 1, 3};
* // 找出目标元素 5 最后一次出现的下标位置,对应下标位置 6
* // 找出目标元素 10 最后一处出现的下标位置,当前用户指定数据不存在,返回 -1
*/
/**
* @param arr 用户提供数组
* @param num 指定数字最后一次出现小标位置
* @param number 指定数字
*
* @return 返回对应下标,若指定数字在数组中不存在,则返回 -1
*/
int output_the_subscript (int arr[], int number, int num);
int main(int argc, char const *argv[])
{
int arr[10] = {1, 3, 5, 7, 1, 3, 5, 7, 1, 3};
int number = 5;
int num = -2;
int a = output_the_subscript(arr, number, num);
if (a != -1)
{
cout << " '5' 在数组中最后一次出现的下标位置为" << a <<endl;
}
else
{
cout << "您输入的数字不在数组中" <<endl;
}
return 0;
}
int output_the_subscript (int arr[], int number, int num)
{
for (int i = 0; i < 10; i++)
{
if (number == arr[i])
{
num = i;
}
}
if(num == -2)
{
num = -1;
}
return num;
}
|
2201_76097352/learning-records
|
ac2/数组练习题/04_找出指定元素在数组中最后一次出现的下标位置.cpp
|
C++
|
unknown
| 1,233
|
package com.neusoft.Shixun;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/MyBatisPlusConfig.java
|
Java
|
unknown
| 669
|
package com.neusoft.Shixun;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@MapperScan("com.neusoft.Shixun.dao")
@EnableCaching
public class ShixunApplication {
public static void main(String[] args) {
SpringApplication.run(ShixunApplication.class, args);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/ShixunApplication.java
|
Java
|
unknown
| 472
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.dto.RoomDto;
import com.neusoft.Shixun.po.Bed;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.BedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/BedController")
public class BedController {
@Autowired
private BedService bedService;
@GetMapping("/getAllBeds")
public ResponseBean<List<Bed>> getAllBeds() {
return bedService.getAllBeds();
}
@GetMapping("/getAllAccessBeds")
// 查询空闲床位
public ResponseBean<List<Bed>> getAllAccessBeds() {
return bedService.getAllAccessBeds();
}
@GetMapping("/{id}")
public ResponseBean<Bed> getBedById(@PathVariable Integer id) {
return bedService.getBedById(id);
}
@PostMapping
public ResponseBean<Integer> addBed(@RequestBody Bed bed) {
return bedService.addBed(bed);
}
@PutMapping("/UpdateBed")
// 更新床位信息
public ResponseBean<Integer> updateBed(@RequestBody Bed bed) {
return bedService.updateBed(bed);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteBed(@PathVariable Integer id) {
return bedService.deleteBed(id);
}
@GetMapping("/getAllRoomsByFloor")
// 查询所有房间
public ResponseBean<List<RoomDto>> getAllRoomsByFloor() {
return bedService.getAllRoomsByFloor();
}
@GetMapping("/getFreeBedsByRoom")
// 查询房间空床位
public ResponseBean<List<Bed>> getFreeBedsByRoom(@RequestParam String roomNumber) {
return bedService.getFreeBedsByRoom(roomNumber);
}
@GetMapping("/changeBed")
// 换床位
public ResponseBean<Integer> changeBed(Integer oldBedId, Integer newBedId, Integer clientId) {
return bedService.changeBed(oldBedId, newBedId, clientId);
}
@GetMapping("/getAllBedsByRoom")
public ResponseBean<List<Bed>> getAllBedsByRoom(@RequestParam String roomNumber) {
return bedService.getAllBedsByRoom(roomNumber);
}
@GetMapping("/getBedByCon")
// 根据房间号和床号查床位
public ResponseBean<Bed> getBedByCon(String roomNumber, String bedNumber){
return bedService.getBedByCon(roomNumber, bedNumber);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/BedController.java
|
Java
|
unknown
| 2,400
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.dto.BedUsageDetailDto;
import com.neusoft.Shixun.po.BedUsage;
import com.neusoft.Shixun.po.Client;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.BedUsageService;
import com.neusoft.Shixun.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/BedUsagesController")
public class BedUsageController {
@Autowired
private BedUsageService bedUsageService;
@Autowired
private ClientService clientService;
@GetMapping
public ResponseBean<List<BedUsage>> getAllBedUsages() {
return bedUsageService.getAllBedUsages();
}
@GetMapping("/queryByCondition")
// 多条件查询
public ResponseBean<List<BedUsage>> getBedUsageByCondition(@RequestParam String clientName, @RequestParam LocalDate startDate, @RequestParam boolean isCurrent) {
Client client = clientService.getClientByName(clientName).getData();
if (client != null) {
return bedUsageService.getBedUsageByCondition(client.getClientId(), startDate, isCurrent);
}
return null;
}
@GetMapping("/getBedUsageDetails")
// 多条件查询,连接床位表,客户表
public ResponseBean<List<BedUsageDetailDto>> getBedUsageDetails(
@RequestParam(required = false) String clientName,
@RequestParam(required = false) String admissionDate,
@RequestParam(required = false) Boolean isCurrent) {
return bedUsageService.getBedUsageDetails(clientName, admissionDate, isCurrent);
}
@PostMapping
public ResponseBean<Integer> addBedUsage(@RequestBody BedUsage bedUsage) {
return bedUsageService.addBedUsage(bedUsage);
}
@PutMapping("/updateBedUsage")
// 只能修改床位的结束时间
public ResponseBean<Integer> updateBedUsage(@RequestBody BedUsage bedUsage) {
return bedUsageService.updateBedUsage(bedUsage);
}
@DeleteMapping("/deleteBedUsage")
// 逻辑删除旧床位使用信息(更改为失效)
public ResponseBean<Integer> deleteBedUsage(@RequestParam Integer id) {
BedUsage bedUsage = bedUsageService.getBedUsageById(id).getData();
if (bedUsage != null) {
bedUsage.setIsCurrent(false);
}
return bedUsageService.deleteBedUsage(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/BedUsageController.java
|
Java
|
unknown
| 2,548
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CareItem;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CareItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/CareItemController")
public class CareItemController {
@Autowired
private CareItemService careItemService;
@GetMapping("/getAllCareItems")
public ResponseBean<List<CareItem>> getAllCareItems() {
return careItemService.getAllCareItems();
}
@GetMapping("/getCareItemsByCondition")
// 多条件查询
public ResponseBean<List<CareItem>> getCareItemsByCondition(
@RequestParam(required = false) String status,
@RequestParam(required = false) String itemName) {
return careItemService.getCareItemsByCondition(itemName, status);
}
@GetMapping("/{id}")
public ResponseBean<CareItem> getCareItemById(@PathVariable Integer id) {
return careItemService.getCareItemById(id);
}
@PostMapping("/addCareItem")
// 添加护理项目
public ResponseBean<Integer> addCareItem(@RequestBody CareItem careItem) {
return careItemService.addCareItem(careItem);
}
@PutMapping("/updateCareItem")
// 修改护理项目信息 如果状态修改为停用需要直接剔除护理级别项目列表中的对应的记录
public ResponseBean<Integer> updateCareItem(@RequestBody CareItem careItem) {
return careItemService.updateCareItem(careItem);
}
@DeleteMapping("/deleteCareItem")
// 护理项目逻辑删除
public ResponseBean<Integer> deleteCareItem(@RequestParam Integer id) {
return careItemService.deleteCareItem(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/CareItemController.java
|
Java
|
unknown
| 1,856
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CareLevel;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CareLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/CareLevelController")
public class CareLevelController {
@Autowired
private CareLevelService careLevelService;
@GetMapping("/getAllCareLevels")
// 查询护理等级列表(默认启用)
public ResponseBean<List<CareLevel>> getAllCareLevels() {
return careLevelService.getAllCareLevels();
}
@GetMapping("/{id}")
public ResponseBean<CareLevel> getCareLevelById(@PathVariable Integer id) {
return careLevelService.getCareLevelById(id);
}
@GetMapping("/getCareLevelByStatus")
// 根据状态查询护理级别
public ResponseBean<List<CareLevel>> getCareLevelByStatus(@RequestParam String status) {
return careLevelService.getAllCareLevelsByStatus(status);
}
@PostMapping("/addCareLevel")
// 添加护理级别(护理级别名称和状态)
public ResponseBean<Integer> addCareLevel(@RequestBody CareLevel careLevel) {
return careLevelService.addCareLevel(careLevel);
}
@PutMapping("/updateCareLevel")
// 修改护理级别,只能修改其状态
public ResponseBean<Integer> updateCareLevel(@RequestBody CareLevel careLevel) {
careLevel.setLevelId(careLevel.getLevelId());
return careLevelService.updateCareLevel(careLevel);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteCareLevel(@PathVariable Integer id) {
return careLevelService.deleteCareLevel(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/CareLevelController.java
|
Java
|
unknown
| 1,797
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CareRecord;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CareRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/CareRecordController")
public class CareRecordController {
@Autowired
private CareRecordService careRecordService;
@GetMapping
public ResponseBean<List<CareRecord>> getAllCareRecords() {
return careRecordService.getAllCareRecords();
}
@GetMapping("/{id}")
public ResponseBean<CareRecord> getCareRecordById(@PathVariable Integer id) {
return careRecordService.getCareRecordById(id);
}
@GetMapping("/getCareRecordByClientId")
// 根据客户id查询护理记录
public ResponseBean<List<CareRecord>> getCareRecordByClientId(@RequestParam Integer id) {
return careRecordService.getCareRecordByClientId(id);
}
@GetMapping("/getCareRecordByCareTakerId")
// 健康管家查询自己客户的护理记录,可以根据姓名模糊查询
public ResponseBean<List<CareRecord>> getCareRecordByCareTakerId(@RequestParam Integer careTakerId, @RequestParam(required = false) String clientName) {
return careRecordService.getCareRecordByCareTakerId(careTakerId, clientName);
}
@PostMapping("/addCareRecord")
// 添加护理记录,同时更新客户护理项目数量
public ResponseBean<Integer> addCareRecord(@RequestBody CareRecord careRecord) {
return careRecordService.addCareRecord(careRecord);
}
@PutMapping("/{id}")
public ResponseBean<Integer> updateCareRecord(@PathVariable Integer id, @RequestBody CareRecord careRecord) {
careRecord.setRecordId(id);
return careRecordService.updateCareRecord(careRecord);
}
@DeleteMapping("/deleteCareRecord")
// 护理记录逻辑删除
public ResponseBean<Integer> deleteCareRecord(@RequestParam Integer id) {
return careRecordService.deleteCareRecord(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/CareRecordController.java
|
Java
|
unknown
| 2,136
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CaretakerClient;
import com.neusoft.Shixun.po.Client;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CaretakerClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/CaretakerClientController")
public class CaretakerClientController {
@Autowired
private CaretakerClientService caretakerClientService;
@GetMapping
public ResponseBean<List<CaretakerClient>> getAllCaretakerClients() {
return caretakerClientService.getAllCaretakerClients();
}
@GetMapping("/{id}")
public ResponseBean<CaretakerClient> getCaretakerClientById(@PathVariable Integer id) {
return caretakerClientService.getCaretakerClientById(id);
}
@GetMapping("/getCaretakerClientByCaretakerId")
// 根据健康管家id查询健康管家服务的的客户,可以根据姓名模糊查询
public ResponseBean<List<Client>> getCaretakerClientByCaretakerId(@RequestParam Integer id, @RequestParam(required = false) String clientName) {
return caretakerClientService.getCaretakerClientByCaretakerId(id, clientName);
}
@PostMapping("/addCaretakerClient")
// 给客户新增健康管家,给客户id和健康管家id
public ResponseBean<Integer> addCaretakerClient(@RequestParam Integer clientId, @RequestParam Integer caretakerId) {
return caretakerClientService.addCaretakerClient(clientId, caretakerId);
}
@PutMapping("/{id}")
public ResponseBean<Integer> updateCaretakerClient(@PathVariable Integer id, @RequestBody CaretakerClient caretakerClient) {
caretakerClient.setRelationId(id);
return caretakerClientService.updateCaretakerClient(caretakerClient);
}
@DeleteMapping("/deleteCaretakerClient")
// 移除某客户的管家,给客户id即可
public ResponseBean<Integer> deleteCaretakerClient(@RequestParam Integer clientId) {
return caretakerClientService.deleteCaretakerClient(clientId);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/CaretakerClientController.java
|
Java
|
unknown
| 2,156
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.service.impl.ChatServiceImpl;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import java.nio.charset.StandardCharsets;
@RestController
@RequestMapping("/ChatClientController")
@CrossOrigin("*")
public class ChatClientController {
private final ChatClient chatClient;
private final ChatServiceImpl chatService;
@Autowired
public ChatClientController(ChatClient.Builder builder, ChatServiceImpl chatService) {
this.chatClient = builder.build();
this.chatService = chatService;
}
@PostMapping("/chat")
public String generateResponse(String msg) {
// 链式调用:构建提示 -> 发送请求 -> 获取文本响应
return null;
}
@GetMapping("/tj")
public String nextDay(@RequestParam(value = "query") String query) {
Prompt prompt = new Prompt(query);
String str = chatClient.prompt(prompt).tools(chatService)
.call()
.content();
System.out.println(str);
return str;
}
@GetMapping("/tj2")
public ResponseEntity<StreamingResponseBody> nextDay2(@RequestParam(value = "query") String query) {
Prompt prompt = new Prompt(query);
// 创建 StreamingResponseBody 对象
StreamingResponseBody stream = outputStream -> {
// 使用 chatClient 获取响应内容
String str = chatClient.prompt(prompt).tools(chatService)
.call()
.content();
// 将内容写入输出流
outputStream.write(str.getBytes(StandardCharsets.UTF_8));
outputStream.flush();
};
// 返回 ResponseEntity 包装的 StreamingResponseBody
return ResponseEntity.ok(stream);
}
@GetMapping("/explain")
// 指定问题和AI回答语气,默认健康专家
public String explain(@RequestParam String problem, @RequestParam(value = "style" ,defaultValue = "健康专家") String y){
// 用户消息
return chatClient.prompt()
.system(s -> s.text("以{style}风格回答").param("style", y)) // 系统消息含占位符
.user(problem) // 用户消息
.call()
.content();
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/ChatClientController.java
|
Java
|
unknown
| 2,607
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.dto.CheckoutRequestWithClientDto;
import com.neusoft.Shixun.po.CheckoutRequest;
import com.neusoft.Shixun.po.OutgoingRequest;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CheckoutRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/CheckoutRequestController")
public class CheckoutRequestController {
@Autowired
private CheckoutRequestService checkoutRequestService;
@GetMapping
public ResponseBean<List<CheckoutRequest>> getAllCheckoutRequests() {
return checkoutRequestService.getAllCheckoutRequests();
}
@GetMapping("/getCheckoutRequests")
// 条件查询
public ResponseBean<List<CheckoutRequestWithClientDto>> getCheckoutRequests(
@RequestParam(required = false) String clientName,
@RequestParam(required = false) String isSelfCare) {
return checkoutRequestService.getCheckoutRequests(clientName, isSelfCare);
}
@GetMapping("/getCheckoutRequestsByCareTakerId")
// 健康管家查询自己服务客户的退住申请
public ResponseBean<List<CheckoutRequestWithClientDto>> getCheckoutRequestsByCareTakerId(
@RequestParam Integer careTakerId,
@RequestParam(required = false) String clientName) {
return checkoutRequestService.getCheckoutRequestsByCareTakerId(careTakerId, clientName);
}
@PostMapping("/passCheckoutRequest")
// 通过退住审核
public ResponseBean<Integer> passCheckoutRequest(@RequestBody CheckoutRequest checkoutRequest) {
return checkoutRequestService.passCheckoutRequest(checkoutRequest);
}
@GetMapping("/{id}")
public ResponseBean<CheckoutRequest> getCheckoutRequestById(@PathVariable Integer id) {
return checkoutRequestService.getCheckoutRequestById(id);
}
@PostMapping("/addCheckoutRequest")
// 健康管家提出退住申请
public ResponseBean<Integer> addCheckoutRequest(@RequestBody CheckoutRequest checkoutRequest) {
return checkoutRequestService.addCheckoutRequest(checkoutRequest);
}
@PutMapping("/{id}")
public ResponseBean<Integer> updateCheckoutRequest(@PathVariable Integer id, @RequestBody CheckoutRequest checkoutRequest) {
checkoutRequest.setRequestId(id);
return checkoutRequestService.updateCheckoutRequest(checkoutRequest);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteCheckoutRequest(@PathVariable Integer id) {
return checkoutRequestService.deleteCheckoutRequest(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/CheckoutRequestController.java
|
Java
|
unknown
| 2,733
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.dto.ClientCareItemDto;
import com.neusoft.Shixun.po.CareItem;
import com.neusoft.Shixun.po.ClientCareItem;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.ClientCareItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/ClientCareItemController")
public class ClientCareItemController {
@Autowired
private ClientCareItemService clientCareItemService;
@GetMapping
public ResponseBean<List<CareItem>> getAllClientCareItems() {
return clientCareItemService.getAllCareItems();
}
@GetMapping("/{id}")
public ResponseBean<ClientCareItem> getClientCareItemById(@PathVariable Integer id) {
return clientCareItemService.getClientCareItemById(id);
}
@GetMapping("/getClientCareItemsByClientId")
// 根据客户Id查询客户的护理项目信息
public ResponseBean<List<ClientCareItemDto>> getClientCareItemsByClientId(Integer clientId) {
return clientCareItemService.getClientCareItemsByClientId(clientId);
}
@GetMapping("/getClientCareItemsClientNotHave")
// 查询客户没有的护理项目
public ResponseBean<List<CareItem>> getClientCareItemsClientNotHave(Integer clientId) {
return clientCareItemService.getClientCareItemsClientNotHave(clientId);
}
@PostMapping("/addClientCareItemByGroup")
// 批量给客户添加护理项目
public ResponseBean<Integer> addClientCareItemByGroup(@RequestParam Integer clientId, @RequestParam Integer levelId, @RequestBody List<ClientCareItem> clientCareItems) {
return clientCareItemService.addClientCareItemByGroup(clientId, levelId, clientCareItems);
}
@PostMapping("/addClientCareItem")
// 给客户添加客户没有的护理项目,给客户id,项目id,数量,购买时间,过期时间,封装成@RequestBody
public ResponseBean<Integer> addClientCareItem(@RequestBody ClientCareItem clientCareItem) {
return clientCareItemService.addClientCareItem(clientCareItem);
}
@PutMapping("/updateClientCareItem")
// 续费已有的项目, 要给客户id,项目id,续费后的数量,以及到期时间,封装成@RequestBody
public ResponseBean<Integer> updateClientCareItem(@RequestBody ClientCareItem clientCareItem) {
return clientCareItemService.updateClientCareItem(clientCareItem);
}
@DeleteMapping("/deleteClientCareItem")
// 移除客户的护理项目
public ResponseBean<Integer> deleteClientCareItem(@RequestParam Integer clientId, @RequestParam Integer itemId) {
return clientCareItemService.deleteClientCareItem(clientId, itemId);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/ClientCareItemController.java
|
Java
|
unknown
| 2,832
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CareLevel;
import com.neusoft.Shixun.po.ClientCareSetting;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.ClientCareSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/ClientCareSettingController")
public class ClientCareSettingController {
@Autowired
private ClientCareSettingService clientCareSettingService;
@GetMapping
public ResponseBean<List<ClientCareSetting>> getAllClientCareSettings() {
return clientCareSettingService.getAllClientCareSettings();
}
@GetMapping("/{id}")
public ResponseBean<ClientCareSetting> getClientCareSettingById(@PathVariable Integer id) {
return clientCareSettingService.getClientCareSettingById(id);
}
@GetMapping("/getClientCareSettingByClientId")
// 根据客户id查询客户护理级别信息
public ResponseBean<CareLevel> getClientCareSettingByClientId(@RequestParam Integer id) {
return clientCareSettingService.getClientCareSettingByClientId(id);
}
@PostMapping("/addClientCareSetting")
// 给客户设置护理级别
public ResponseBean<Integer> addClientCareSetting(@RequestBody ClientCareSetting setting) {
return clientCareSettingService.addClientCareSetting(setting);
}
@PutMapping("/updateClientCareSetting")
// 修改客户的护理级别(传入客户id和级别id)
public ResponseBean<Integer> updateClientCareSetting(
@RequestBody ClientCareSetting setting) {
return clientCareSettingService.updateClientCareSetting(setting);
}
@DeleteMapping("/deleteClientCareSetting")
// 移除客户的护理级别,同时级联删除客户的护理项目
public ResponseBean<Integer> deleteClientCareSetting(@RequestParam Integer clientId) {
return clientCareSettingService.deleteClientCareSetting(clientId);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/ClientCareSettingController.java
|
Java
|
unknown
| 2,068
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CaretakerClient;
import com.neusoft.Shixun.po.Client;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CaretakerClientService;
import com.neusoft.Shixun.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/ClientController")
public class ClientController {
@Autowired
private ClientService clientService;
@GetMapping("/queryAll")
// 查询所有老人,默认自理
public ResponseBean<List<Client>> getAllClients() {
return clientService.getAllClients();
}
@GetMapping("/getClientsWithoutCaretaker")
// 询没有管家的客户,可以根据客户名条件查询
public ResponseBean<List<Client>> getClientsWithoutCaretaker(@RequestParam(required = false) String clientName) {
return clientService.getClientsWithoutCaretaker(clientName);
}
@GetMapping("/getClientsByCaretaker")
// 查询某个健康管家服务的客户,根据客户名进行模糊查询
public ResponseBean<List<Client>> getClientsByCaretaker(@RequestParam Integer caretakerId, @RequestParam(required = false) String clientName) {
return clientService.getClientsByCaretaker(caretakerId, clientName);
}
@GetMapping("/queryByCon")
// 条件查询
public ResponseBean<List<Client>> getClientsByCondition(
@RequestParam(required = false) String clientName,
@RequestParam(required = false) String isSelfCare) {
return clientService.getClientsByCondition(clientName, isSelfCare);
}
@PostMapping("/addClient")
// 登记入住信息
public ResponseBean<Integer> addClient(@RequestBody Client client) {
return clientService.addClient(client);
}
@PutMapping("/updateClient")
public ResponseBean<Integer> updateClient(@RequestBody Client client) {
client.setClientId(client.getClientId());
return clientService.updateClient(client);
}
@DeleteMapping("/deleteClient")
// 逻辑删除
public ResponseBean<Integer> deleteClient(@RequestParam Integer id) {
Client client = clientService.getClientById(id).getData();
if (client != null) {
client.setActive(false);
}
return clientService.updateClient(client);
}
@GetMapping("/getClientById")
// 按客户id查询客户
public ResponseBean<Client> getClientById(Integer clientId) {
return clientService.getClientById(clientId);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/ClientController.java
|
Java
|
unknown
| 2,661
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.ClientMealPreferences;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.ClientMealPreferencesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/ClientMealPreferencesController")
public class ClientMealPreferencesController {
@Autowired
private ClientMealPreferencesService clientMealPreferencesService;
@GetMapping("/getAllClientMealPreferences")
// 查看客户日常膳食配置
public ResponseBean<List<ClientMealPreferences>> getAllClientMealPreferences() {
return clientMealPreferencesService.getAllClientMealPreferences();
}
@GetMapping("/{id}")
public ResponseBean<ClientMealPreferences> getClientMealPreferencesById(@PathVariable Integer id) {
return clientMealPreferencesService.getClientMealPreferencesById(id);
}
@PostMapping("/addClientMealPreferences")
// 客户日常膳食配置
public ResponseBean<Integer> addClientMealPreferences(@RequestBody ClientMealPreferences clientMealPreferences) {
return clientMealPreferencesService.addClientMealPreferences(clientMealPreferences);
}
@PutMapping("/updateClientMealPreferences")
// 修改膳食配置
public ResponseBean<Integer> updateClientMealPreferences(@RequestBody ClientMealPreferences clientMealPreferences) {
return clientMealPreferencesService.updateClientMealPreferences(clientMealPreferences);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteClientMealPreferences(@PathVariable Integer id) {
return clientMealPreferencesService.deleteClientMealPreferences(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/ClientMealPreferencesController.java
|
Java
|
unknown
| 1,817
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.CareItem;
import com.neusoft.Shixun.po.LevelItem;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.LevelItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.logging.Level;
@RestController
@CrossOrigin("*")
@RequestMapping("/LevelItemController")
public class LevelItemController {
@Autowired
private LevelItemService levelItemService;
@GetMapping
public ResponseBean<List<LevelItem>> getAllLevelItems() {
return levelItemService.getAllLevelItems();
}
@GetMapping("/{id}")
public ResponseBean<LevelItem> getLevelItemById(@PathVariable Integer id) {
return levelItemService.getLevelItemById(id);
}
@GetMapping("/getCareItemsByLevelId")
// 根据级别id查询该级别下的项目
public ResponseBean<List<CareItem>> getCareItemsByLevelId(@RequestParam Integer id) {
return levelItemService.getCareItemsByLevelId(id);
}
@GetMapping("/getCareItemsNotBelongsToLevelId")
// 根据级别id查询不在该级别下的项目
public ResponseBean<List<CareItem>> getCareItemsNotBelongsToLevelId(@RequestParam Integer id) {
return levelItemService.getCareItemsNotBelongsToLevelId(id);
}
@PostMapping("/addCareItemToLevelItem")
// 添加护理项目到某个护理级别中
public ResponseBean<Integer> addCareItemToLevelItem(@RequestParam Integer careLevelId, @RequestParam Integer careItemId ) {
return levelItemService.addCareItemToLevelItem(careLevelId, careItemId);
}
@PostMapping
public ResponseBean<Integer> addLevelItem(@RequestBody LevelItem levelItem) {
return levelItemService.addLevelItem(levelItem);
}
@PutMapping("/{id}")
public ResponseBean<Integer> updateLevelItem(@PathVariable Integer id, @RequestBody LevelItem levelItem) {
levelItem.setLevelItemId(id);
return levelItemService.updateLevelItem(levelItem);
}
@DeleteMapping("/deleteLevelItem")
// 删除护理级别下的项目
public ResponseBean<Integer> deleteLevelItem(@RequestParam Integer levelId, @RequestParam Integer itemId) {
return levelItemService.deleteLevelItem(levelId, itemId);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/LevelItemController.java
|
Java
|
unknown
| 2,364
|
package com.neusoft.Shixun.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.neusoft.Shixun.po.MealPlan;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.MealPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin("*")
@RequestMapping("/MealPlanController")
public class MealPlanController {
@Autowired
private MealPlanService mealPlanService;
@GetMapping("/getAllMealPlans")
// 查询膳食日历,默认启用
public ResponseBean<List<MealPlan>> getAllMealPlans() {
return mealPlanService.getAllMealPlans();
}
@GetMapping("/{id}")
public ResponseBean<MealPlan> getMealPlanById(@PathVariable Integer id) {
return mealPlanService.getMealPlanById(id);
}
@PostMapping("/addMealPlan")
// 添加膳食计划
public ResponseBean<Integer> addMealPlan(@RequestBody Map<String, Object> map) {
MealPlan mealPlan = new MealPlan();
mealPlan.setDate(LocalDate.parse((String) map.get("date")));
mealPlan.setMealType((String) map.get("mealType"));
mealPlan.setStatus((String) map.get("status"));
mealPlan.setNotes((String) map.get("notes"));
// items字段转为JSON字符串
ObjectMapper mapper = new ObjectMapper();
String itemsJson = null;
try {
itemsJson = mapper.writeValueAsString(map.get("items"));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
mealPlan.setItems(itemsJson);
return mealPlanService.addMealPlan(mealPlan);
}
@PutMapping("/updateMealPlan")
// 修改膳食计划
public ResponseBean<Integer> updateMealPlan(@RequestBody Map<String, Object> map) {
MealPlan mealPlan = new MealPlan();
mealPlan.setPlanId((Integer) map.get("planId"));
mealPlan.setDate(LocalDate.parse((String) map.get("date")));
mealPlan.setMealType((String) map.get("mealType"));
mealPlan.setStatus((String) map.get("status"));
mealPlan.setNotes((String) map.get("notes"));
// items字段转为JSON字符串
ObjectMapper mapper = new ObjectMapper();
String itemsJson = null;
try {
itemsJson = mapper.writeValueAsString(map.get("items"));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
mealPlan.setItems(itemsJson);
return mealPlanService.updateMealPlan(mealPlan);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteMealPlan(@PathVariable Integer id) {
return mealPlanService.deleteMealPlan(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/MealPlanController.java
|
Java
|
unknown
| 2,890
|
package com.neusoft.Shixun.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.Shixun.po.Message;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin("*")
@RequestMapping("/MessageController")
public class MessageController {
@Autowired
private MessageService messageService;
@PostMapping("/saveMessage")
public ResponseEntity<Map<String, Object>> saveMessage(@RequestBody Message message) {
Map<String, Object> response = new HashMap<>();
try {
messageService.saveMessage(message);
response.put("status", 200);
response.put("msg", "预约成功");
} catch (Exception e) {
response.put("status", 500);
response.put("msg", "预约失败: " + e.getMessage());
}
return ResponseEntity.ok(response);
}
@GetMapping("/getMessagesByCareTakerId")
public ResponseBean<List<Message>> getMessagesByCareTakerId(Integer careTakerId) {
return messageService.getMessagesByCareTakerId(careTakerId);
}
@PostMapping("/emergency")
public ResponseBean<Integer> emergency(@RequestBody Message message) {
return messageService.emergency(message);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/MessageController.java
|
Java
|
unknown
| 1,545
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.dto.OutgoingRequestWithClientDto;
import com.neusoft.Shixun.po.Bed;
import com.neusoft.Shixun.po.BedUsage;
import com.neusoft.Shixun.po.OutgoingRequest;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.BedService;
import com.neusoft.Shixun.service.BedUsageService;
import com.neusoft.Shixun.service.OutgoingRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/OutgoingRequestController")
public class OutgoingRequestController {
@Autowired
private OutgoingRequestService outgoingRequestService;
@GetMapping
public ResponseBean<List<OutgoingRequest>> getAllOutgoingRequests() {
return outgoingRequestService.getAllOutgoingRequests();
}
@GetMapping("/getOutgoingRequests")
// 条件查询
public ResponseBean<List<OutgoingRequestWithClientDto>> getOutgoingRequests(
@RequestParam(required = false) String clientName,
@RequestParam(required = false) String isSelfCare) {
return outgoingRequestService.getOutgoingRequests(clientName, isSelfCare);
}
@GetMapping("/getOutgoingRequestsByCareTakerId")
// 健康管家查询自己服务客户的外出申请
public ResponseBean<List<OutgoingRequestWithClientDto>> getOutgoingRequestsByCareTakerId(
@RequestParam Integer careTakerId,
@RequestParam(required = false) String clientName) {
return outgoingRequestService.getOutgoingRequestsByCareTakerId(careTakerId, clientName);
}
@PostMapping("/passOutgoingRequest")
// 通过外出审核
public ResponseBean<Integer> passOutgoingRequest(@RequestBody OutgoingRequest outgoingRequest) {
return outgoingRequestService.passOutgoingRequest(outgoingRequest);
}
@GetMapping("/{id}")
public ResponseBean<OutgoingRequest> getOutgoingRequestById(@PathVariable Integer id) {
return outgoingRequestService.getOutgoingRequestById(id);
}
@PostMapping("/addOutgoingRequest")
// 健康管家提出外出申请
public ResponseBean<Integer> addOutgoingRequest(@RequestBody OutgoingRequest outgoingRequest) {
return outgoingRequestService.addOutgoingRequest(outgoingRequest);
}
@PutMapping("/updateOutgoingRequest")
// 登记归来时间
public ResponseBean<Integer> updateOutgoingRequest(@RequestBody OutgoingRequest outgoingRequest) {
return outgoingRequestService.updateOutgoingRequest(outgoingRequest);
}
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteOutgoingRequest(@PathVariable Integer id) {
return outgoingRequestService.deleteOutgoingRequest(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/OutgoingRequestController.java
|
Java
|
unknown
| 2,831
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.redisdao.RedisDao;
import com.neusoft.Shixun.service.impl.RedisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.concurrent.TimeUnit;
@RestController
@CrossOrigin("*")
@RequestMapping("/RedisController")
public class RedisController {
@Autowired
private RedisServiceImpl redisServiceImpl;
@PostMapping("/saveNotTimeLimit")
public ResponseBean<String> saveNotTimeLimit(String key, String value) {
redisServiceImpl.set(key, value);
return new ResponseBean<>("success");
}
@PostMapping("/saveTimeLimit")
public ResponseBean<String> saveTimeLimit(String key, String value) {
// 暂时先设置成50s
redisServiceImpl.set(key, value, 50, TimeUnit.SECONDS);
return new ResponseBean<>("success");
}
@GetMapping("/read")
public ResponseBean<String> read(String key) {
return redisServiceImpl.get(key);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/RedisController.java
|
Java
|
unknown
| 1,096
|
package com.neusoft.Shixun.controller;
import com.neusoft.Shixun.po.User;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.RedisService;
import com.neusoft.Shixun.service.UserService;
import com.neusoft.Shixun.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin("*")
@RestController
@RequestMapping("/UserController")
@Tag(name = "用户管理接口")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RedisService redisService;
@Operation(summary = "登录", description = "用户登录,验证用户名和密码,成功后返回JWT令牌")
@Parameters({
@Parameter(name = "username", description = "账号", required = true),
@Parameter(name = "password", description = "密码", required = true)
})
@ApiResponses({
@ApiResponse(responseCode = "200", description = "登录成功", content = @Content(schema = @Schema(implementation = ResponseBean.class))),
@ApiResponse(responseCode = "401", description = "用户名或密码错误")
})
@PostMapping("/login")
public ResponseBean<Map<String, Object>> login(@RequestParam String username, @RequestParam String password) {
// 验证用户登录信息
ResponseBean<User> userResponseBean = userService.login(username, password);
User user = userResponseBean.getData();
if (user != null) {
// 创建Claims
Map<String, String> claims = new HashMap<>();
claims.put("userId", user.getUserId().toString());
claims.put("role", user.getRole());
// 生成JWT令牌
String token = JwtUtil.createToken(claims);
System.out.println(token);
// 返回令牌
Map<String, Object> response = new HashMap<>();
response.put("token", token);
return new ResponseBean<>(response);
} else {
return new ResponseBean<>(401, "用户名或密码错误");
}
}
@Operation(summary = "退出登录", description = "用户退出登录,将JWT令牌加入黑名单")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "退出成功"),
@ApiResponse(responseCode = "401", description = "未授权")
})
@PostMapping("/logout")
public ResponseBean<Void> logout(@RequestHeader("Authorization") String authorizationHeader) {
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) {
return new ResponseBean<>(401, "未授权");
}
String token = authorizationHeader.substring(7); // 去掉"Bearer "前缀
redisService.addTokenToBlacklist(token);
return new ResponseBean<>();
}
@Operation(summary = "获取所有用户", description = "获取系统中所有用户的信息")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "获取成功", content = @Content(schema = @Schema(implementation = ResponseBean.class)))
})
@GetMapping("/getAllUsers")
public ResponseBean<List<User>> getAllUsers() {
return userService.getAllUsers();
}
@Operation(summary = "根据用户ID获取用户信息", description = "根据用户ID查询用户详细信息")
@Parameter(name = "id", description = "用户ID", required = true)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "获取成功", content = @Content(schema = @Schema(implementation = ResponseBean.class))),
@ApiResponse(responseCode = "404", description = "用户不存在")
})
@GetMapping("/{id}")
public ResponseBean<User> getUserById(@PathVariable Integer id) {
return userService.getUserById(id);
}
@Operation(summary = "根据姓名查询用户信息", description = "根据姓名查询用户信息")
@Parameter(name = "username", description = "管家姓名", required = true)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "获取成功", content = @Content(schema = @Schema(implementation = ResponseBean.class)))
})
@GetMapping("/getUserByName")
public ResponseBean<User> getUserByName(@RequestParam String username) {
return userService.getUserByName(username);
}
@Operation(summary = "根据管家姓名查询管家信息", description = "根据管家姓名查询管家信息")
@Parameter(name = "careTakerName", description = "管家姓名", required = false)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "获取成功", content = @Content(schema = @Schema(implementation = ResponseBean.class)))
})
@GetMapping("/getUserByCareTakerName")
public ResponseBean<List<User>> getUserByCareTakerName(@RequestParam(required = false) String careTakerName) {
return userService.getUserByCareTakerName(careTakerName);
}
@Operation(summary = "添加用户", description = "添加新用户")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "添加成功", content = @Content(schema = @Schema(implementation = ResponseBean.class)))
})
@PostMapping("/addUser")
public ResponseBean<Integer> addUser(@RequestBody User user) {
return userService.addUser(user);
}
@Operation(summary = "更新用户信息", description = "更新用户信息")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "更新成功", content = @Content(schema = @Schema(implementation = ResponseBean.class)))
})
@PutMapping("/updateUser")
public ResponseBean<Integer> updateUser(@RequestBody User user) {
return userService.updateUser(user);
}
@Operation(summary = "删除用户", description = "根据用户ID删除用户")
@Parameter(name = "id", description = "用户ID", required = true)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "删除成功", content = @Content(schema = @Schema(implementation = ResponseBean.class))),
@ApiResponse(responseCode = "404", description = "用户不存在")
})
@DeleteMapping("/{id}")
public ResponseBean<Integer> deleteUser(@PathVariable Integer id) {
return userService.deleteUser(id);
}
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/controller/UserController.java
|
Java
|
unknown
| 6,912
|
package com.neusoft.Shixun.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.Shixun.dto.RoomDto;
import com.neusoft.Shixun.po.Bed;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface BedDao extends BaseMapper<Bed> {
// 在这里可以定义一些自定义的SQL操作(如果有需要)
// 查询所有楼层的房间号,去重
@Select("SELECT DISTINCT SUBSTRING(room_number, 1, 1) AS floor, room_number " +
"FROM beds " +
"ORDER BY floor, room_number")
List<RoomDto> getAllRoomsByFloor();
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/dao/BedDao.java
|
Java
|
unknown
| 655
|
package com.neusoft.Shixun.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.Shixun.dto.BedUsageDetailDto;
import com.neusoft.Shixun.po.BedUsage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
@Mapper
public interface BedUsageDao extends BaseMapper<BedUsage> {
// 在这里可以定义一些自定义的SQL操作(如果有需要)
// 多条件查询床位使用信息,联动客户表和床位表
@Select("<script>" +
"SELECT c.client_name, c.client_id, b.room_number, b.bed_number, " +
" bu.start_date, bu.end_date, bu.is_current, bu.bed_id, bu.usage_id " +
"FROM clients c " +
"JOIN bed_usage bu ON c.client_id = bu.client_id " +
"JOIN beds b ON bu.bed_id = b.bed_id " +
"WHERE 1=1 " +
"<if test='clientName != null and clientName != \"\"'>" +
" AND c.client_name LIKE CONCAT('%', #{clientName}, '%') " +
"</if> " +
"<if test='admissionDate != null and admissionDate != \"\"'>" +
" AND c.admission_date = #{admissionDate} " +
"</if> " +
"<if test='isCurrent != null'>" +
" AND bu.is_current = #{isCurrent} " +
"</if> " +
"</script>")
List<BedUsageDetailDto> getBedUsageDetailsByConditions(
@Param("clientName") String clientName,
@Param("admissionDate") String admissionDate,
@Param("isCurrent") Boolean isCurrent);
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/dao/BedUsageDao.java
|
Java
|
unknown
| 1,643
|
package com.neusoft.Shixun.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.Shixun.po.CareItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface CareItemDao extends BaseMapper<CareItem> {
// 在这里可以定义一些自定义的SQL操作(如果有需要)
// 自定义查询
@Select("<script>" +
"SELECT item_id, item_name, price, status, cycle, times, description " +
"FROM care_items " +
"WHERE (is_active IS NULL OR is_active != '移除') " + // 添加默认条件
"<if test='itemName != null and itemName != \"\"'>" +
" AND item_name LIKE CONCAT('%', #{itemName}, '%') " +
"</if> " +
"<if test='status != null and status != \"\"'>" +
" AND status = #{status} " +
"</if> " +
"</script>")
List<CareItem> getCareItemsByConditions(@Param("itemName") String itemName, @Param("status") String status);
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/dao/CareItemDao.java
|
Java
|
unknown
| 1,111
|
package com.neusoft.Shixun.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.Shixun.po.CareLevel;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CareLevelDao extends BaseMapper<CareLevel> {
// 在这里可以定义一些自定义的SQL操作(如果有需要)
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/dao/CareLevelDao.java
|
Java
|
unknown
| 324
|
package com.neusoft.Shixun.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.Shixun.po.CareRecord;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CareRecordDao extends BaseMapper<CareRecord> {
// 在这里可以定义一些自定义的SQL操作(如果有需要)
}
|
2301_76230122/shixun_houduan
|
Shixun/src/main/java/com/neusoft/Shixun/dao/CareRecordDao.java
|
Java
|
unknown
| 327
|