Update Codes

This commit is contained in:
Hmtsai 2023-12-31 14:21:19 +08:00
parent d20ef25e32
commit f248f11ab6
6 changed files with 164 additions and 51 deletions

View File

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

View File

@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int *arr_in = new int[n + 1];
int *arr_tmp = new int[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr_in[i];
}
for (int i = 1; i <= n; i++) {
arr_tmp[arr_in[i]]++;
}
int k = 1;
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= arr_tmp[i]; j++) {
arr_in[k++] = i;
}
}
for (int i = 1; i <= n; i++) {
cout << arr_in[i];
}
delete[] arr_in;
delete[] arr_tmp;
return 0;
}

View File

@ -0,0 +1,46 @@
#include <iostream>
int main()
{
int n,i,j,k;
std::cin >> n;
int listn[n];
for (int i = 0; i < n; i++)
{
std::cin >> listn[i];
}
for (i = 0; i < n; i++)
{
for (j = i-1; j>=0; j--)
{
if(listn[j]<listn[i]){
break;
}
}
if(j!=i-1){
int tmp = listn[i];
for(k=i-1;k>j;k--){
listn[k+1]=listn[k];
}
listn[k+1]=tmp;
}
/* 另一种方式:
** int num = listn[i];
** int j = i - 1;
** while ((j >= 0) && (listn[j] > num))
** {
** listn[j + 1] = listn[j];
** j--;
** }
** listn[j + 1] = num;
*/
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";
}
std::cout << std::endl;
return 0;
}

View File

@ -19,10 +19,13 @@ int main()
minIndex = j;
}
}
if (!minIndex == i)
{
int tmp = listn[i];
listn[i] = listn[minIndex];
listn[minIndex] = tmp;
}
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";

View File

@ -24,53 +24,81 @@ public:
}
void nextDay()
{
if ( mouth==2 ) {
if ( isLeapYear() ) {
if ( day+1>29 ) {
if (mouth == 2)
{
if (isLeapYear())
{
if (day + 1 > 29)
{
mouth++;
day = 1;
} else {
day++;
}
} else {
if ( day+1>28 ) {
mouth++;
day=1;
} else {
else
{
day++;
}
}
} else if ( isBigMouth ( mouth ) ) {
if ( day+1>31 ) {
else
{
if (day + 1 > 28)
{
mouth++;
day = 1;
} else {
}
else
{
day++;
}
} else if ( mouth==12 ) {
if ( day+1>31 ) {
}
}
else if (isBigMouth(mouth))
{
if (day + 1 > 31)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
else if (mouth == 12)
{
if (day + 1 > 31)
{
year++;
mouth = 1;
day = 1;
} else {
}
else
{
day++;
}
} else {
if ( day+1>20 ) {
}
else
{
if (day + 1 > 20)
{
mouth++;
day = 1;
} else {
}
else
{
day++;
}
}
}
private:
int day, mouth, year;
int isBigMouth(int inMouth)
{
int bigMouth[7] = {1, 3, 5, 7, 8, 10};
for ( int i=0; i<7; i++ ) {
if ( inMouth==bigMouth[i] ) {
for (int i = 0; i < 7; i++)
{
if (inMouth == bigMouth[i])
{
return 1;
}
}