Advertisement
Guest User

Untitled

a guest
Mar 20th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <vector>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. float degToRad( string s){
  10.     s.replace(s.find(","),s.find(","), ".");
  11.     return (stof(s) * (M_PI  / 180));
  12. }
  13.  
  14.  
  15. int main()
  16. {
  17.     string LON, LAT, destination ,DEFIB, intermediate;
  18.     int N,cpt;
  19.     cin >> LON >> LAT >> N; cin.ignore();
  20.    
  21.     float d = 10000000, x, y, d1, latitude, longitude, temp,
  22.            longe = degToRad(LON), latit = degToRad(LAT);
  23.  
  24.     for (size_t i = 0; i < N; i++) {
  25.        
  26.         getline(cin, DEFIB);
  27.        
  28.         // Vector of string to save tokens
  29.         vector <string> tokens;
  30.         // stringstream class check1
  31.         stringstream check1(DEFIB);
  32.  
  33.         // Tokenizing w.r.t. ';'
  34.         cpt=0;
  35.         while(getline(check1, intermediate, ';'))
  36.         {
  37.             switch (cpt){
  38.                 case 4 :
  39.                     longitude = degToRad(intermediate);
  40.                     break;
  41.                 case 5 :
  42.                     latitude = degToRad(intermediate);
  43.                     break;
  44.                 default :
  45.                     break;
  46.             }
  47.             cpt++;
  48.         }
  49.  
  50.         x = (longe - longitude) * cos((latitude+latit)/2);
  51.         y = latit - latitude;
  52.         d1 = sqrt(pow(x,2) + pow(y,2)) * 6371.0;
  53.  
  54.         if ( d1 <= d ){
  55.             d = d1;
  56.             temp=DEFIB.find(';')+1;
  57.             destination = DEFIB.substr(temp,DEFIB.find(';',temp)-temp);
  58.             if (destination == "Caisse Primaire d'Assurance Maladie")
  59.                 cerr << "CPAM : " << d << endl;
  60.             else if (destination=="Caisse d'assurance retraite et de la Sante au travail")
  61.                 cerr << "Sante travail : " << d << endl;
  62.             cerr << "mini dist = " << d << endl;
  63.  
  64.         }
  65.     }
  66.     cout << destination << endl;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement