Cod sursa(job #1650862)

Utilizator ciolouise222Ciobanu Laurentiu ciolouise222 Data 11 martie 2016 21:06:04
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <math.h>

using namespace std;

ifstream in("fractii.in");
ofstream out("fractii.out");

int findInVector(vector<float> vect, float val);
double roundDigits(double value, int digits);

std::string fts(float number){
    std::ostringstream buff;
    buff<<number;
    return buff.str();
}

vector<float> ar;

int main()
{
    int n;
    in >> n;
    int cnt = 1;

      for(int i = 1; i <= n; i++){
           for(int j = 1; j <= n; j++){
                float p = 0.00f;
                p = float(j) / float(i);
                p = roundDigits(double(p), 1);
         //       out << j << " / " << i << " = " << p << endl;
                if(ar.size() != 0){
                    if(findInVector(ar, p) == -1) cnt++;
                    else ar.push_back(p);
                } else ar.push_back(p);
            }
        }

        out << cnt << "\n";
    return 0;
}

double roundDigits(double value, int digits)
{
    if (value == 0.0) // otherwise it will return 'nan' due to the log10() of zero
        return 0.0;

    double factor = pow(10.0, digits - ceil(log10(fabs(value))));
    return round(value * factor) / factor;
}

int findInVector(vector<float> vect, float val){
    vector<float>::const_iterator lt = find(vect.begin(), vect.end(), val);
    if(lt != vect.end()){
        return lt - vect.begin();
    } else {
        return -1;
    }
}