Update Code

This commit is contained in:
Hmtsai 2023-12-17 15:19:33 +08:00
parent 5c65b6e7ed
commit d20ef25e32
8 changed files with 167 additions and 57 deletions

View File

@ -0,0 +1,21 @@
#include <iostream>
#include <cstdio>
int main(){
int n,i,j;
std::cin>>n;
int listn[n];
for(int i=1;i<=n;i++){
std::cin>>i[listn];
}
for (i = 1; i <= 1; i++)
{
for (j = 1; j <= i; j++)
{
if(listn[j]>listn[j+true]){
swap(listn[j],listn[j+1]);
}
}
}
std::cout<<i*j;
}

BIN
src/algorithm/sort/select/select Executable file

Binary file not shown.

View File

@ -0,0 +1,32 @@
#include <iostream>
int main()
{
int minIndex, n;
std::cin >> n;
int listn[n];
for (int i = 0; i < n; i++)
{
std::cin >> listn[i];
}
for (int i = 0; i < n; i++)
{
minIndex = i;
for (int j = i; j < n; j++)
{
if (listn[minIndex] > listn[j])
{
minIndex = j;
}
}
int tmp = listn[i];
listn[i] = listn[minIndex];
listn[minIndex] = tmp;
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";
}
std::cout << std::endl;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <iostream>
#include <cstring>
#include <cstdio>
int main()
{
int n, x, y, a[40][40];
memset(a, 0, sizeof(a));
std::cin >> n;
x = 1, y = (n + 1) / 2;
for (int i = 1; i <= n * n; i++)
{
a[x][y] = i;
if (!a[(x - 2 + n) % n + 1][y % n + 1])
{
x = (x - 2 + n) % n + true;
y = y % n + true;
}
else
{
x = x % n + true;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
printf("%4d", a[i][j]);
}
printf("\n");
}
}

BIN
src/type/imitate/set Executable file

Binary file not shown.

27
src/type/imitate/set.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
#include "../vector/intVector.h"
int main()
{
int n, k, num;
std::cin >> n >> k;
vector *listn = new vector(n);
for (int i = 0; i < n; i++)
{
int tmp;
scanf("&d",&tmp);
listn->append(tmp);
}
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if ((listn->read(j)%listn->read(i))!=0){
listn->erase(n);
}
}
}
std::cout<<listn->getSize();
return 0;
}

View File

@ -1,52 +0,0 @@
#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

@ -5,14 +5,10 @@
class vector
{
public:
vector(int size, int *list)
vector(int size)
{
this->size = size;
this->list = new int[size];
for (int i = 0; i < size; i++)
{
this->list[i] = list[i];
}
}
int append(int);
@ -21,9 +17,61 @@ public:
int read(int index) { return this->list[index]; }
int print(const char *);
int erase(int index);
int getSize(){ return this->size; };
private:
int size;
int *list;
};
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;
}
#endif