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 <iostream>
#include <cstdio> #include <cstdio>
int main(){ int main()
int n,i,j; {
std::cin>>n; int n, i, j;
std::cin >> n;
int listn[n]; int listn[n];
for(int i=1;i<=n;i++){ for (int i = 0; i < n; i++)
std::cin>>i[listn]; {
std::cin >> listn[i];
} }
for (i = 1; i <= 1; i++) for (i = 1; i <= 1; i++)
{ {
for (j = 1; j <= i; j++) for (j = 1; j <= i; j++)
{ {
if(listn[j]>listn[j+true]){ if (listn[j] > listn[j + true])
swap(listn[j],listn[j+1]); {
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,9 +19,12 @@ int main()
minIndex = j; minIndex = j;
} }
} }
int tmp = listn[i]; if (!minIndex == i)
listn[i] = listn[minIndex]; {
listn[minIndex] = tmp; int tmp = listn[i];
listn[i] = listn[minIndex];
listn[minIndex] = tmp;
}
} }
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {

View File

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