Share 739. daily temperatures c++,

ngoccanhpepito

New member
#C ++, #CPP, #Programming, #cấu trúc dữ liệu ## 739. Nhiệt độ hàng ngày trong C ++

Trong hướng dẫn này, chúng tôi sẽ học cách tìm nhiệt độ tối thiểu và tối đa hàng ngày trong một danh sách nhiệt độ nhất định bằng C ++.Chúng tôi sẽ sử dụng cấu trúc dữ liệu sau để lưu trữ nhiệt độ:

`` `
nhiệt độ cấu trúc {
ngày trong ngày;
nhiệt độ kép;
};
`` `

Trường `Day` lưu trữ vào ngày nhiệt độ và lĩnh vực 'nhiệt độ` lưu trữ nhiệt độ vào ngày đó.

Chúng ta có thể tìm thấy nhiệt độ tối thiểu và tối đa hàng ngày bằng thuật toán sau:

1. Khởi tạo hai biến, `min_temate` và` max_temate`, đến nhiệt độ đầu tiên trong danh sách.
2. Đối với mỗi nhiệt độ trong danh sách, hãy làm như sau:
* Nếu nhiệt độ nhỏ hơn `min_temate`, thì hãy cập nhật` min_temate` lên nhiệt độ.
* Nếu nhiệt độ lớn hơn `max_temate`, thì hãy cập nhật` max_temate` lên nhiệt độ.
3. In các giá trị của `min_temate` và` max_temate`.

Dưới đây là một ví dụ về cách sử dụng thuật toán này:

`` `
#include <Istream>
#include <Vector>

sử dụng không gian tên STD;

nhiệt độ cấu trúc {
ngày trong ngày;
nhiệt độ kép;
};

int main () {
// Tạo một vectơ nhiệt độ.
Vector <Mules> Nhiệt độ = {
{1, 50},
{2, 45},
{3, 40},
{4, 35},
{5, 30},
};

// Khởi tạo nhiệt độ tối thiểu và tối đa.
Double min_temate = Nhiệt độ [0]. Nhiệt độ;
Double max_temate = Nhiệt độ [0]. Nhiệt độ;

// Tìm nhiệt độ tối thiểu và tối đa hàng ngày.
for (int i = 1; i <nhiệt độ.size (); i ++) {
if (nhiệt độ .temate <min_temate) {
min_temate = Nhiệt độ .Tem Nhiệt độ;
}
if (nhiệt độ .temate> max_temate) {
MAX_TEMMETATURE = Nhiệt độ .Tem Nhiệt độ;
}
}

// in nhiệt độ tối thiểu và tối đa hàng ngày.
cout << "Nhiệt độ tối thiểu là" << min_temate << endl;
cout << "Nhiệt độ tối đa là" << MAX_TEMATERATIATE << endl;

trả lại 0;
}
`` `

Chương trình này sẽ in đầu ra sau:

`` `
Nhiệt độ tối thiểu là 30.0
Nhiệt độ tối đa là 50,0
`` `

### hashtags

* #C ++
* #CPP
* #Programming
* #cấu trúc dữ liệu
=======================================
#C++, #CPP, #Programming, #data-structures ## 739. Daily Temperatures in C++

In this tutorial, we will learn how to find the daily minimum and maximum temperatures in a given list of temperatures using C++. We will use the following data structure to store the temperatures:

```
struct Temperature {
int day;
double temperature;
};
```

The `day` field stores the day of the temperature, and the `temperature` field stores the temperature on that day.

We can find the daily minimum and maximum temperatures using the following algorithm:

1. Initialize two variables, `min_temperature` and `max_temperature`, to the first temperature in the list.
2. For each temperature in the list, do the following:
* If the temperature is less than `min_temperature`, then update `min_temperature` to the temperature.
* If the temperature is greater than `max_temperature`, then update `max_temperature` to the temperature.
3. Print the values of `min_temperature` and `max_temperature`.

Here is an example of how to use this algorithm:

```
#include <iostream>
#include <vector>

using namespace std;

struct Temperature {
int day;
double temperature;
};

int main() {
// Create a vector of temperatures.
vector<Temperature> temperatures = {
{1, 50},
{2, 45},
{3, 40},
{4, 35},
{5, 30},
};

// Initialize the minimum and maximum temperatures.
double min_temperature = temperatures[0].temperature;
double max_temperature = temperatures[0].temperature;

// Find the daily minimum and maximum temperatures.
for (int i = 1; i < temperatures.size(); i++) {
if (temperatures.temperature < min_temperature) {
min_temperature = temperatures.temperature;
}
if (temperatures.temperature > max_temperature) {
max_temperature = temperatures.temperature;
}
}

// Print the daily minimum and maximum temperatures.
cout << "The minimum temperature was " << min_temperature << endl;
cout << "The maximum temperature was " << max_temperature << endl;

return 0;
}
```

This program will print the following output:

```
The minimum temperature was 30.0
The maximum temperature was 50.0
```

### Hashtags

* #C++
* #CPP
* #Programming
* #data-structures
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top