Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Read inputs from stdin. Write outputs to stdout.
- #include <locale>
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <cstdlib>
- #define _USE_MATH_DEFINES
- using namespace std;
- int main()
- {
- string posx, posy;
- int count;
- cin >> posx;
- cin >> posy;
- cin >> count;
- int tmp;
- tmp = posx.find(",");
- posx.replace(tmp, tmp,".");
- tmp = posy.find(",");
- posy.replace(tmp, tmp,".");
- double fposx = atof(posx.c_str());
- double fposy = atof(posy.c_str());
- fposx = (fposx/180) * M_PI;
- fposy = (fposy/180) * M_PI;
- string line, spos;
- double mindist = 999999999999;
- double cposx, cposy, distx, disty;
- cin.ignore();
- string which;
- for (int i=0; i<count; i++)
- {
- double dist;
- getline(cin, line);
- spos = line.substr(line.rfind(";;")+2);
- posx = spos.substr(0,spos.find(";"));
- posy = spos.substr(spos.find(";")+1);
- cposx = atof(posx.c_str());
- cposy = atof(posy.c_str());
- cposx = (cposx/180) * M_PI;
- cposy = (cposy/180) * M_PI;
- distx = (fposx - cposx)*cos((fposx+cposx)/2);
- disty = fposy - cposy;
- dist = (distx*distx + disty*disty);
- cout << dist << endl;
- if (dist<mindist)
- {
- mindist = dist;
- which = line;
- }
- }
- cout << which;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement