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

View File

@ -4,73 +4,101 @@ using namespace std;
class Tdate
{
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;
mouth=setMouth;
year=setYear;
day = setDay;
mouth = setMouth;
year = setYear;
}
int isLeapYear()
{
return ( ( year%4==0&&year%100!=0 ) || ( year%400==0 ) );
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
}
void printYear()
{
cout<<year<<"/"<<mouth<<"/"<<day<<endl;
cout << year << "/" << mouth << "/" << day << endl;
}
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++;
day = 1;
}
} 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
{
day++;
}
}
}
else if (isBigMouth(mouth))
{
if (day + 1 > 31)
{
mouth++;
day=1;
} else {
day = 1;
}
else
{
day++;
}
} else if ( mouth==12 ) {
if ( day+1>31 ) {
}
else if (mouth == 12)
{
if (day + 1 > 31)
{
year++;
mouth=1;
day=1;
} else {
mouth = 1;
day = 1;
}
else
{
day++;
}
} else {
if ( day+1>20 ) {
}
else
{
if (day + 1 > 20)
{
mouth++;
day=1;
} else {
day = 1;
}
else
{
day++;
}
}
}
private:
int day,mouth,year;
int isBigMouth ( int inMouth )
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] ) {
int bigMouth[7] = {1, 3, 5, 7, 8, 10};
for (int i = 0; i < 7; i++)
{
if (inMouth == bigMouth[i])
{
return 1;
}
}
@ -80,10 +108,10 @@ private:
int main()
{
Tdate date ( 31,12,2011 );
Tdate date(31, 12, 2011);
date.printYear();
date.nextDay();
date.printYear();
cout<<date.isLeapYear() <<endl;
cout << date.isLeapYear() << endl;
return 0;
}