Pagini recente » Cod sursa (job #2840825) | Cod sursa (job #2821919) | Cod sursa (job #116170) | Cod sursa (job #1714542) | Cod sursa (job #2605355)
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;
#define RAD 6371000
ifstream fin("in.txt");
ofstream fout("out.txt");
class Map {
public:
int N;
struct coordonates {
vector <int> timestamp;
vector <double> lat;
vector <double> lon;
vector <double> altitude;
} coord;
vector < tuple <string, string, int> > flight;
};
void read(Map& m) {
fin >> m.N;
for (int i = 0; i < m.N; i++) {
int t, l1, l2, altitude;
char c[5000];
fin >> c;
int start = 0;
int finish = 0;
while (c[finish] != ',')finish++;
c[finish] = 0;
m.coord.lat.push_back(atof(c));
start = finish + 1;
finish = finish + 1;
while (c[finish] != ',')finish++;
c[finish] = 0;
m.coord.lon.push_back(atof(c + start));
m.coord.altitude.push_back(atof(c + finish + 1));
}
}
double formula(double x, double x0, double x1, double y0, double y1) {
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
void Level4(Map& m) {
int n;
fin >> n;
for (int i = 0; i < n; i++) {
string s;
int time;
fin >> s >> time;
ifstream flights("usedFlights\\" + s + ".csv");
string in, out;
flights >> in >> out;
int takeOff;
flights >> takeOff;
flights >> m.N;
int oldt = time;
float oldlat = 0, oldlon = 0, oldalt = 0;
int t = time;
float lat=0, lon=0, alt=0;
for (int j = 0; j < m.N; j++) {
oldt = t;
oldlat = lat;
oldlon = lon;
oldalt = alt;
char c[500000];
flights >> c;
int start = 0;
int finish = 0;
while (c[finish] != ',')finish++;
c[finish] = 0;
t = atoi(c);
start = finish + 1;
finish = finish + 1;
while (c[finish] != ',')finish++;
c[finish] = 0;
lat = atof(c + start);
start = finish + 1;
finish = finish + 1;
while (c[finish] != ',')finish++;
c[finish] = 0;
lon = atof(c + start);
alt = atof(c + finish + 1);
if (t + takeOff > time)
break;
//cout << t << ' ' << lat << ' ' << lon << ' ' << alt << '\n';
}
flights.close();
if (oldt + takeOff== time) {
fout << fixed << setprecision(7) << oldlat << ' ' << oldlon << ' ' << oldalt << '\n';
continue;
}
if (t + takeOff == time) {
fout << fixed << setprecision(7) << lat << ' ' << lon << ' ' << alt << '\n';
continue;
}
/*
if (oldt > t) {
swap(oldt, t);
}
if (oldalt > alt) {
swap(oldalt, alt);
}
if (oldlon > lon) {
swap(oldlon, lon);
}
if (oldlat > lat) {
swap(oldlat, lat);
}
*/
oldt += takeOff;
t += takeOff;
double x, y, z;
x = formula(time, oldt, t, oldlat, lat);
y = formula(time, oldt, t, oldlon, lon);
z = formula(time, oldt, t, oldalt, alt);
fout << fixed << setprecision(7) << x << ' ' << y << ' ' << z << '\n';
}
}
void afisareFlightCount(Map& m) {
for (int i = 0; i < m.N; i++)
for (int j = i + 1; j < m.N; j++) {
string a = get<0>(m.flight[i]);
string b = get<1>(m.flight[i]);
string c = get<0>(m.flight[j]);
string d = get<1>(m.flight[j]);
if (a + "," + b > c + "," + d || (a + "," + b == c + "," + d && get<2>(m.flight[i]) < get<2>(m.flight[j]))) {
swap(m.flight[i], m.flight[j]);
}
}
for (int i = 0; i < m.N; i++) {
string a = get<0>(m.flight[i]);
string b = get<1>(m.flight[i]);
int TotalCounter = 1;
int counter = 1;
int time = get<2>(m.flight[i]);
while (i + counter < m.N && a == get<0>(m.flight[i + counter]) && b == get<1>(m.flight[i + counter]))
if (time == get<2>(m.flight[i + counter]))
counter++;
else TotalCounter++, counter++, time = get<2>(m.flight[i + counter - 1]);
i += counter - 1;
fout << a << ' ' << b << ' ' << TotalCounter << '\n';
}
}
void calcFormula(Map& m) {
for (int i = 0; i < m.N; i++) {
double N = RAD;
long double pi = atan(1) * 4;
long double phi = m.coord.lat[i];
phi = phi * pi/180;
long double lambda = m.coord.lon[i];
lambda = lambda * pi/180;
long double h = m.coord.altitude[i];
//cout << phi << ' ' << lambda << ' ' << h << '\n';
long double x = (N + h) * cosl(phi) * cosl(lambda);
//cout << cosl (phi) << ' ' << cosl(lambda) << '\n';
long double y = (N + h) * cosl(phi) * sinl(lambda);
//cout << cosl(phi) << ' ' << sinl(lambda) << '\n';
long double z = (N + h) * sinl(phi);
fout << fixed << setprecision(7) << x << ' ' << y << ' ' << z << '\n';
}
}
/*
void afiseazaMinSiMax(Map& m) {
int minT = m.timestamp[0], maxT = m.timestamp[0];
float minLat = m.lat[0], maxLat = m.lat[0];
float minLong = m.lon[0], maxLong = m.lon[0];
float maxAlt = m.altitude[0];
for (int i = 0; i < m.N; i++) {
if (minT > m.timestamp[i])
minT = m.timestamp[i];
if (maxT < m.timestamp[i])
maxT = m.timestamp[i];
if (minLat > m.lat[i])
minLat = m.lat[i];
if (maxLat < m.lat[i])
maxLat = m.lat[i];
if (minLong > m.lon[i])
minLong = m.lon[i];
if (maxLong < m.lon[i])
maxLong = m.lon[i];
if (maxAlt < m.altitude[i])
maxAlt = m.altitude[i];
}
fout << minT << ' ' << maxT << '\n' << minLat << ' ' << maxLat << '\n' << minLong << ' ' << maxLong << '\n' << maxAlt;
}*/
int main() {
Map m;
Level4(m);
fin.close();
fout.close();
}