Advertisement
Leeen

IDZ#RIGHT#

Nov 27th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include<fstream>
  2. #include<vector>
  3. #include<iomanip>
  4. #include<cmath>
  5.  
  6. using namespace std;
  7.  
  8. double dx(double direction, double trace)
  9. {
  10.     if (direction == 2 || direction == 4)
  11.         return (sqrt(2)/ 2 * trace);
  12.     else if (direction == 3)
  13.         return trace;
  14.     else if (direction == 6 || direction == 8)
  15.         return (-sqrt(2)/ 2 * trace);
  16.     else if (direction == 7)
  17.         return (-1) * trace;
  18.     return 0;
  19. }
  20.  
  21. double dy(double direction, double trace)
  22. {
  23.     if (direction == 2 || direction == 8)
  24.         return (sqrt(2)/ 2 * trace);
  25.     else if (direction == 1)
  26.         return trace;
  27.     else if (direction == 6 || direction == 4)
  28.         return (-sqrt(2)/ 2* trace);
  29.     else if (direction == 5)
  30.         return (-1) * trace;
  31.     return 0;
  32. }
  33.  
  34. int main()
  35. {
  36.     ifstream fileIn;
  37.     fileIn.open("INPUT.TXT");
  38.     int N;
  39.     fileIn >> N;
  40.     if(N>40)
  41.         N = 40;
  42.      
  43.     vector <int> traces;
  44.     vector <int> directions;
  45.  
  46.     int k;
  47.     int l;
  48.     int n = N;
  49.     while (n > 0)
  50.     {
  51.         fileIn >> l;
  52.         directions.push_back(l);
  53.         fileIn >> k;
  54.         traces.push_back(k);
  55.         n--;
  56.     }
  57.     fileIn.close();
  58.  
  59.     double x = 0;
  60.     double y = 0;
  61.     for (int i = 0; i < N; i++)
  62.     {
  63.             x = x + dx(directions[i], traces[i]);
  64.              
  65.             y = y + dy(directions[i], traces[i]);
  66.     }
  67.  
  68.     ofstream fileOut;
  69.     fileOut.setf(ios::fixed);
  70.     fileOut.precision(3);
  71.  
  72.     fileOut.open("OUTPUT.txt");
  73.      
  74.  
  75.     fileOut << x << ' ' << y;
  76.  
  77.     fileOut.close();
  78.  
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement