Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
🐛 6_007
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Oct 26, 2023
1 parent 81d378c commit 83fb18e
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions Problem_006/6_007.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@

using namespace std;

void Nhap(int[], int&);
int GTLN(int[],int);
void Nhap(int[], int &);
int GTLN(int[], int);

int main()
{
int a[5000];
int n;
Nhap(a, n);
cout << GTLN(a, n);
return 0;
int a[5000];
int n;
Nhap(a, n);
cout << GTLN(a, n);
return 0;
}

void Nhap(int a[], int& n)
void Nhap(int a[], int &n)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
}

int GTLN(int a[],int n)
int GTLN(int a[], int n)
{
int max2 = a[0];
int max = a[0];
for (int i = 0; i < n; i++)
if (max < a[i])
max = a[i];
for (int i = n-1; i>=0; i--)
if (max > a[i] && max2 <= a[i])
max2 = a[i];
if (max == max2)
return 0;
return max2;
int max2 = -1;
int max = a[0];
for (int i = 0; i < n; i++)
if (max < a[i])
max = a[i];
for (int i = n - 1; i >= 0; i--)
if (max > a[i] && max2 < a[i])
max2 = a[i];
if (max2 == -1)
return 0;
return max2;
}

0 comments on commit 83fb18e

Please sign in to comment.