CSES - Datatähti 2024 alku - Results
Submission details
Task:Säähavainnot
Sender:maweiyin24562
Submission time:2023-11-07 22:51:41 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:43:33: error: 'setprecision' was not declared in this scope
   43 |                 cout << fixed <<setprecision(2)<< predictions[j];
      |                                 ^~~~~~~~~~~~

Code

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        vector<double> temperatures(24);
        for (int j = 0; j < 24; j++) {
            cin >> temperatures[j];
        }

        vector<double> predictions(12);
        for (int j = 12; j < 24; j++) {
            // Calculate the average of the previous 12 hours
            double sum = 0.0;
            int count = 0;
            for (int k = j - 12; k < j; k++) {
                if (temperatures[k] != -1.0) {
                    sum += temperatures[k];
                    count++;
                }
            }

            // If there is enough data for prediction, calculate the average
            if (count >= 6) {
                predictions[j - 12] = sum / count;
            } else {
                // If there is insufficient data, use a question mark
                predictions[j - 12] = -1.0;
            }
        }

        // Print the predictions for the next 12 hours
        for (int j = 0; j < 12; j++) {
            if (j > 0) {
                cout << " ";
            }
            if (predictions[j] != -1.0) {
                cout << fixed <<setprecision(2)<< predictions[j];
            } else {
                cout << "?";
            }
        }
        cout << endl;
    }

    return 0;
}