Update Code

This commit is contained in:
Hmtsai 2023-12-17 13:49:07 +08:00
parent 1324b8c9d3
commit 5c65b6e7ed
7 changed files with 258 additions and 1 deletions

94
.vscode/settings.json vendored
View File

@ -1,6 +1,98 @@
{ {
"cmake.configureOnOpen": false, "cmake.configureOnOpen": false,
"files.associations": { "files.associations": {
"iostream": "cpp" "iostream": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"barrier": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cuchar": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"expected": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"source_location": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"hash_set": "cpp",
"format": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"latch": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"scoped_allocator": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"spanstream": "cpp",
"sstream": "cpp",
"stacktrace": "cpp",
"stdexcept": "cpp",
"stdfloat": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"syncstream": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
} }
} }

14
src/type/enum/enum.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin>>n;
for(int i=2;i<sqrt(n);i++){
if(n%i==0){
cout<<"N"<<endl;
return 0;
}
}
cout<<"Y"<<endl;
return 0;
}

View File

@ -0,0 +1,28 @@
#include <iostream>
int main()
{
bool alive[100] = {0};
int f = 0, n, m, t = 0, s = 0;
std::cin >> n >> m;
do
{
t++;
if (t > n)
{
t = 1;
}
if (!alive[t])
{
s++;
}
if (s == m)
{
s = 0;
std::cout << t << ' ';
alive[t] = 1;
f++;
}
} while (f != n);
std::cout << std::endl;
return 0;
}

View File

@ -0,0 +1,21 @@
#include <iostream>
#include <vector>
int main()
{
int n, m;
std::cin >> n >> m;
std::vector<int> alive(n);
for (int i = 0; i < n; i++)
{
alive[i] = i + 1;
}
int cur = 0;
while (alive.size())
{
cur = (cur + m - 1) % alive.size();
std::cout << alive[cur] << " ";
alive.erase(alive.begin() + cur);
}
std::cout << "\n";
}

View File

@ -0,0 +1,52 @@
#include "intVector.h"
int vector::append(int number)
{
int tmp[size++];
for (int i = 0; i < size - 1; i++)
{
tmp[i] = this->list[i];
}
this->list = new int[size];
for (int i = 0; i < size - 1; i++)
{
this->list[i] = tmp[i];
}
this->list[size - 1] = number;
return 0;
}
int vector::print(const char *end)
{
for (int i = 0; i < size; i++)
{
std::cout << this->list[i];
}
std::cout << end;
return 0;
}
int vector::erase(int index)
{
if (index >= size || index < 0)
{
throw "Index is so big or small";
return -1;
}
this->list[index] = 0;
for (int i = index + 1; i < size; i++)
{
this->list[i - 1] = this->list[i];
}
int tmp[size--];
for (int i = 0; i < size; i++)
{
tmp[i] = this->list[i];
}
this->list = new int[size];
for (int i = 0; i < size; i++)
{
this->list[i] = tmp[i];
}
return 0;
}

View File

@ -0,0 +1,29 @@
#ifndef __INTVECTOR_H__
#define __INTVECTOR_H__
#include <iostream>
class vector
{
public:
vector(int size, int *list)
{
this->size = size;
this->list = new int[size];
for (int i = 0; i < size; i++)
{
this->list[i] = list[i];
}
}
int append(int);
int begin() { return this->list[0]; }
int end() { return this->list[size - 1]; }
int read(int index) { return this->list[index]; }
int print(const char *);
int erase(int index);
private:
int size;
int *list;
};
#endif

View File

@ -0,0 +1,21 @@
#include <iostream>
#include "intVector.h"
int main()
{
int test[] = {0, 1, 2, 3};
vector Test(4, test);
Test.print("\n");
Test.append(4);
Test.print("\n");
try{
Test.erase(0);
Test.print("\n");
Test.erase(-1);
}catch(const char * msg){
std::cerr<<msg<<std::endl;
}
Test.print("\n");
std::cout<<Test.begin()<<" "<<Test.end()<<std::endl;
return 0;
}