lequyen719
New member
#C ++, #Maximum Sản phẩm của ba số, #AlGorithM, #Programming ** 628.Sản phẩm tối đa của ba số (C ++) **
Đưa ra một loạt các số nguyên, hãy tìm sản phẩm tối đa của ba số.
**Ví dụ 1:**
`` `
Đầu vào: [1, 2, 3]
Đầu ra: 6
`` `
** Ví dụ 2: **
`` `
Đầu vào: [-1, -2, -3]
Đầu ra: 9
`` `
**Giải pháp:**
`` `C ++
#include <Istream>
#include <Vector>
sử dụng không gian tên STD;
int main () {
vector <Int> nums = {1, 2, 3};
// Tìm sản phẩm tối đa của ba số.
int max1 = nums [0];
int max2 = nums [1];
int max3 = nums [2];
int min1 = nums [0];
int min2 = nums [1];
for (int i = 2; i <nums.size (); i ++) {
if (nums > max1) {
Max3 = Max2;
max2 = max1;
max1 = nums ;
} if if (nums > max2) {
Max3 = Max2;
max2 = nums ;
} if if (nums > max3) {
Max3 = nums ;
}
if (nums <min1) {
min2 = min1;
min1 = nums ;
} khác if (nums <min2) {
min2 = nums ;
}
}
// sản phẩm tối đa của ba số là
// (max1 * max2 * max3) hoặc (min1 * min2 * max3).
int maxProduct = max1 * max2 * max3;
int minproduct = min1 * min2 * max3;
cout << "Sản phẩm tối đa của ba số là" << MaxProduct << endl;
cout << "Sản phẩm tối thiểu của ba số là" << minproaduct << endl;
trả lại 0;
}
`` `
** Hashtags: **
* #C ++
* #Maximum Sản phẩm của ba số
* #AlGorithM
* #Programming
=======================================
#C++, #Maximum product of three numbers, #AlGorithM, #Programming **628. Maximum Product of Three Numbers (C++)**
Given an array of integers, find the maximum product of three numbers.
**Example 1:**
```
Input: [1, 2, 3]
Output: 6
```
**Example 2:**
```
Input: [-1, -2, -3]
Output: 9
```
**Solution:**
```c++
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> nums = {1, 2, 3};
// Find the maximum product of three numbers.
int max1 = nums[0];
int max2 = nums[1];
int max3 = nums[2];
int min1 = nums[0];
int min2 = nums[1];
for (int i = 2; i < nums.size(); i++) {
if (nums > max1) {
max3 = max2;
max2 = max1;
max1 = nums;
} else if (nums > max2) {
max3 = max2;
max2 = nums;
} else if (nums > max3) {
max3 = nums;
}
if (nums < min1) {
min2 = min1;
min1 = nums;
} else if (nums < min2) {
min2 = nums;
}
}
// The maximum product of three numbers is either
// (max1 * max2 * max3) or (min1 * min2 * max3).
int maxProduct = max1 * max2 * max3;
int minProduct = min1 * min2 * max3;
cout << "The maximum product of three numbers is " << maxProduct << endl;
cout << "The minimum product of three numbers is " << minProduct << endl;
return 0;
}
```
**Hashtags:**
* #C++
* #Maximum product of three numbers
* #AlGorithM
* #Programming
Đưa ra một loạt các số nguyên, hãy tìm sản phẩm tối đa của ba số.
**Ví dụ 1:**
`` `
Đầu vào: [1, 2, 3]
Đầu ra: 6
`` `
** Ví dụ 2: **
`` `
Đầu vào: [-1, -2, -3]
Đầu ra: 9
`` `
**Giải pháp:**
`` `C ++
#include <Istream>
#include <Vector>
sử dụng không gian tên STD;
int main () {
vector <Int> nums = {1, 2, 3};
// Tìm sản phẩm tối đa của ba số.
int max1 = nums [0];
int max2 = nums [1];
int max3 = nums [2];
int min1 = nums [0];
int min2 = nums [1];
for (int i = 2; i <nums.size (); i ++) {
if (nums > max1) {
Max3 = Max2;
max2 = max1;
max1 = nums ;
} if if (nums > max2) {
Max3 = Max2;
max2 = nums ;
} if if (nums > max3) {
Max3 = nums ;
}
if (nums <min1) {
min2 = min1;
min1 = nums ;
} khác if (nums <min2) {
min2 = nums ;
}
}
// sản phẩm tối đa của ba số là
// (max1 * max2 * max3) hoặc (min1 * min2 * max3).
int maxProduct = max1 * max2 * max3;
int minproduct = min1 * min2 * max3;
cout << "Sản phẩm tối đa của ba số là" << MaxProduct << endl;
cout << "Sản phẩm tối thiểu của ba số là" << minproaduct << endl;
trả lại 0;
}
`` `
** Hashtags: **
* #C ++
* #Maximum Sản phẩm của ba số
* #AlGorithM
* #Programming
=======================================
#C++, #Maximum product of three numbers, #AlGorithM, #Programming **628. Maximum Product of Three Numbers (C++)**
Given an array of integers, find the maximum product of three numbers.
**Example 1:**
```
Input: [1, 2, 3]
Output: 6
```
**Example 2:**
```
Input: [-1, -2, -3]
Output: 9
```
**Solution:**
```c++
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> nums = {1, 2, 3};
// Find the maximum product of three numbers.
int max1 = nums[0];
int max2 = nums[1];
int max3 = nums[2];
int min1 = nums[0];
int min2 = nums[1];
for (int i = 2; i < nums.size(); i++) {
if (nums > max1) {
max3 = max2;
max2 = max1;
max1 = nums;
} else if (nums > max2) {
max3 = max2;
max2 = nums;
} else if (nums > max3) {
max3 = nums;
}
if (nums < min1) {
min2 = min1;
min1 = nums;
} else if (nums < min2) {
min2 = nums;
}
}
// The maximum product of three numbers is either
// (max1 * max2 * max3) or (min1 * min2 * max3).
int maxProduct = max1 * max2 * max3;
int minProduct = min1 * min2 * max3;
cout << "The maximum product of three numbers is " << maxProduct << endl;
cout << "The minimum product of three numbers is " << minProduct << endl;
return 0;
}
```
**Hashtags:**
* #C++
* #Maximum product of three numbers
* #AlGorithM
* #Programming