fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. int main(){
  6. std::vector<std::vector<double>> Towers{ { 26.4, 46.3, -3.0, 19.8 }, { -20.9, 39.8, 33.2, -4.1 }, { -26.2, -26.7, 26.1, -0.3 }, { -29.2, -12.0, 24.3, 45.1 } };
  7. std::vector<double> Ghost{ 0.4, 30, 7.8, 19.1 };
  8. std::vector<std::pair<int,double>> Res;
  9. double T = 0;
  10.  
  11. for (std::size_t i = 0; i < Towers.size(); i++){
  12. T = 0;
  13. for (std::size_t j = 0; j < Towers[i].size(); j++){
  14. T += std::abs(Ghost[j] - Towers[i][j]);
  15. }
  16. if (Res.size() == 0){
  17. Res.push_back(std::make_pair(static_cast<int>(i), T));
  18. continue;
  19. }
  20. if (T < Res[0].second){
  21. Res.clear();
  22. Res.push_back(std::make_pair(static_cast<int>(i), T));
  23. continue;
  24. }
  25. if (T == Res[0].second){
  26. Res.push_back(std::make_pair(static_cast<int>(i), T));
  27. continue;
  28. }
  29. }
  30.  
  31. int i = 0;
  32. std::cout << "in:"<<std::endl;
  33. for (auto& v : Towers){
  34. std::cout << static_cast<char>('A' + i++)<<'[';
  35. for (auto& o : v){
  36. std::cout << o << ',';
  37. }
  38. std::cout << "]"<<std::endl;
  39. }
  40. std::cout << std::endl;
  41.  
  42. std::cout << "out:";
  43. for (auto& o : Res) std::cout << static_cast<char>('A' + o.first) << '@' << o.second;
  44. std::cout << std::endl << std::endl;
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
in:
A[26.4,46.3,-3,19.8,]
B[-20.9,39.8,33.2,-4.1,]
C[-26.2,-26.7,26.1,-0.3,]
D[-29.2,-12,24.3,45.1,]

out:A@53.8