Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <vector>
- #include <cmath>
- #define M_PI 3.14159265358979323846
- using namespace std;
- double cFloatToD(string cfloat){
- int pos = string::npos;
- while((pos = cfloat.find(",")) != string::npos){
- cfloat.replace(pos, 1, ".");
- }
- return atof(cfloat.c_str());
- }
- vector<string>* tokenize(vector<string>* intok, string str){
- intok->clear();
- char *pch = new char[str.length()];
- for (int i=0; i<str.length(); i++)
- pch[i] = str.c_str()[i];
- pch[str.length()-1] = 0;
- pch = strtok(pch,";");
- while (pch != NULL){
- intok->push_back(pch);
- pch = strtok(NULL, ";");
- }
- delete[] pch;
- return intok;
- }
- int main(){
- string line,MinName; double selfx, selfy, posx, posy, distx, disty, dist, MinDist=10000;
- cin >> line; selfx = cFloatToD(line); selfx=(selfx/180)*M_PI;
- cin >> line; selfy = cFloatToD(line); selfy=(selfy/180)*M_PI;
- int n; cin >> n;
- cin.ignore();
- for (int i=0; i<n; i++){
- getline(cin, line);
- vector<string>* tokens = new vector<string>;
- tokens = tokenize(tokens, line);
- posx = cFloatToD((*tokens)[tokens->size()-2].c_str()); posx=(posx/180)*M_PI;
- posy = cFloatToD((*tokens)[tokens->size()-1].c_str()); posy=(posy/180)*M_PI;
- distx = (posx - selfx) * cos((selfy+posy)/2);
- disty = (posy - selfy);
- dist = (pow(distx,2) + pow(disty,2)) * 6371;
- if (dist < MinDist){
- MinName = (*tokens)[1];
- MinDist = dist;
- }
- }
- cout << MinName;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement