Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<vector>
- #include<iomanip>
- #include<cmath>
- using namespace std;
- double dx(double direction, double trace)
- {
- if (direction == 2 || direction == 4)
- return (sqrt(2)/ 2 * trace);
- else if (direction == 3)
- return trace;
- else if (direction == 6 || direction == 8)
- return (-sqrt(2)/ 2 * trace);
- else if (direction == 7)
- return (-1) * trace;
- return 0;
- }
- double dy(double direction, double trace)
- {
- if (direction == 2 || direction == 8)
- return (sqrt(2)/ 2 * trace);
- else if (direction == 1)
- return trace;
- else if (direction == 6 || direction == 4)
- return (-sqrt(2)/ 2* trace);
- else if (direction == 5)
- return (-1) * trace;
- return 0;
- }
- int main()
- {
- ifstream fileIn;
- fileIn.open("INPUT.TXT");
- int N;
- fileIn >> N;
- if(N>40)
- N = 40;
- vector <int> traces;
- vector <int> directions;
- int k;
- int l;
- int n = N;
- while (n > 0)
- {
- fileIn >> l;
- directions.push_back(l);
- fileIn >> k;
- traces.push_back(k);
- n--;
- }
- fileIn.close();
- double x = 0;
- double y = 0;
- for (int i = 0; i < N; i++)
- {
- x = x + dx(directions[i], traces[i]);
- y = y + dy(directions[i], traces[i]);
- }
- ofstream fileOut;
- fileOut.setf(ios::fixed);
- fileOut.precision(3);
- fileOut.open("OUTPUT.txt");
- fileOut << x << ' ' << y;
- fileOut.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement