for Robot Artificial Inteligence

1. How to use STL

|

STL

  • STL(or Standard Template Library) is a set of templates used to make the code
  • SIMPLE and EASY TO write
  • how do we use STL?
    • just write #include <bits/stdc++.h>

EXAMPLE (Max, swap)

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a = 5, b = 8, maximum;

    // Maximum from a and b;
    maximum = max(a,b);

    // swapping two value
    swap(a,b); // a= 8, b = 5

    return 0;
}

EXAMPLE(double pow)

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a = 5, b = 8, maximum;

    // Maximum from a and b;
    maximum = max(a,b);

    // swapping two value
    swap(a,b); // a= 8, b = 5

    // double pow (double base, double exponent);

    int number = 2;
    double cubicRoot;

    cubicRoot = pow((double)(number), 1.0/3); // 1(or 3) is of type int / 1.0(or 3.0) is of type double

    cout<<fixed<<setprecision(10)<<cubicRoot<<"\n"; // setprecision is 소수점 반올림
    cout<<fixed<<setprecision(3)<<cubicRoot<<"\n";

    return 0;
}

Comments