CSES - Datatähti 2024 alku - Results
Submission details
Task:Säähavainnot
Sender:cppbetter
Submission time:2023-11-01 23:34:03 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void trig(double*)':
input/code.cpp:60:19: error: 'sin' was not declared in this scope
   60 |         ss << a * sin(i * b + c) + d << " ";
      |                   ^~~

Code

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <numeric>
#include <numbers>

//#define TEST

using namespace std;

stringstream ss;

// y=a*sin(b*x+c)+d
// 
// H=a+d
// H-a=d
//
// L = -a+d
// L -d = -a
// d-L = a
// H-a-L = a
// H-L = 2a
// (H-L)/2 = a
// 
// pi/2 = bx+c 
// pi/2 - bx = c 


void trig(double* data)
{
    double a, b, c, d;

    b = 2.0 * numbers::pi / 24.0;

    double smallestVal = 10000;
    double largestVal = -10000;
    double lowAmpl;

    for (int i = 0; i < 24; i++)
    {
        if (smallestVal > data[i])
        {
            smallestVal =  data[i];
            lowAmpl = i;
        }
        if (largestVal < data[i])
        {
            largestVal = data[i];
        }
    }

    a = (largestVal - smallestVal) / 2;
    d = largestVal - a;
    c = 3 * numbers::pi / 2 - (b * lowAmpl);

    for (int i = 24; i < 24 + 12; i++)
    {
        ss << a * sin(i * b + c) + d << " ";
    }
    ss << "\n";

}

int main()
{
    int n;

#ifdef TEST
    fstream f;

    f.open(__FILE__ "/../../sample-data.txt");

    f >> n;

    for (int i = 0; i < n; i++)
    {
        vector<double> dt;

        for (int j = 0; j < 36; j++)
        {
            double v;
            f >> v;
            dt.push_back(v);
        }

        trig(&dt[0]);
    }

    f.close();
#else
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        vector<double> dt;

        for (int j = 0; j < 24; j++)
        {
            double v;
            cin >> v;
            dt.push_back(v);
        }

        trig(&dt[0]);
    }

    cout << ss.str();
#endif

    return 0;
}