Advertisement
hugol

Untitled

Nov 24th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. // Read inputs from stdin. Write outputs to stdout.
  2.  
  3. #include <locale>
  4. #include <iostream>
  5. #include <string>
  6. #include <math.h>
  7. #include <cstdlib>
  8. #define _USE_MATH_DEFINES
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     string posx, posy;
  15.     int count;
  16.     cin >> posx;
  17.     cin >> posy;
  18.     cin >> count;
  19.     int tmp;
  20.     tmp = posx.find(",");
  21.     posx.replace(tmp, tmp,".");
  22.     tmp = posy.find(",");
  23.     posy.replace(tmp, tmp,".");
  24.    
  25.     double fposx = atof(posx.c_str());
  26.     double fposy = atof(posy.c_str());
  27.    
  28.     fposx = (fposx/180) * M_PI;
  29.     fposy = (fposy/180) * M_PI;
  30.    
  31.     string line, spos;
  32.    
  33.     double mindist = 999999999999;
  34.     double cposx, cposy, distx, disty;
  35.  
  36.     cin.ignore();
  37.     string which;
  38.     for (int i=0; i<count; i++)
  39.     {
  40.         double dist;
  41.         getline(cin, line);
  42.        
  43.         spos = line.substr(line.rfind(";;")+2);
  44.         posx = spos.substr(0,spos.find(";"));
  45.         posy = spos.substr(spos.find(";")+1);
  46.        
  47.         cposx = atof(posx.c_str());
  48.         cposy = atof(posy.c_str());
  49.         cposx = (cposx/180) * M_PI;
  50.         cposy = (cposy/180) * M_PI;
  51.        
  52.         distx = (fposx - cposx)*cos((fposx+cposx)/2);
  53.         disty = fposy - cposy;
  54.         dist = (distx*distx + disty*disty);
  55.         cout << dist << endl;
  56.         if (dist<mindist)
  57.         {
  58.             mindist = dist;
  59.             which = line;
  60.         }
  61.  
  62.     }
  63.    
  64.     cout << which;
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement