Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class Vec {
  6. public:
  7. double x1, x2, x3;
  8. int sz = 0;
  9. Vec(double x1, double x2, double x3) {
  10. this->x1 = x1;
  11. this->x2 = x2;
  12. this->x3 = x3;
  13. }
  14.  
  15. double module() {
  16. return (sqrt(x1*x1 + x2*x2 +x3*x3));
  17. }
  18. };
  19.  
  20. vector<Vec> V;
  21.  
  22. Vec parse(string s) {
  23.  
  24. std::string delimiter = ";";
  25. s = s + delimiter;
  26. size_t pos = 0;
  27. std::string token;
  28. int position = 0;
  29. std::string::size_type sz;
  30. Vec rs = Vec(0,0,0);
  31. while ((pos = s.find(delimiter)) != std::string::npos) {
  32. token = s.substr(0, pos);
  33. double x = stod(token, &sz);
  34. //cout << x << endl;
  35. if ( position == 0 ){
  36. rs.x1 = x;
  37. } else if (position == 1) {
  38. rs.x2 = x;
  39. } else {
  40. rs.x3 = x;
  41. }
  42. s.erase(0, pos + delimiter.length());
  43. position++;
  44. }
  45. rs.sz = position;
  46. return rs;
  47. }
  48.  
  49.  
  50. int main(){
  51. ifstream cin("test.in");
  52.  
  53. for (string s; cin >> s;) {
  54. V.push_back(parse(s));
  55. }
  56.  
  57. Vec sum = Vec(0,0,0);
  58. for (auto it: V) {
  59. sum.x1 += it.x1;
  60. sum.x2 += it.x2;
  61. sum.x3 += it.x3;
  62. }
  63. for (auto it: V) {
  64. if (it.module() >= sum.module()) {
  65. cout << fixed << setprecision(3) << (it.x1 < 0 ? "" : "") << it.x1 << "i"<<(it.x2 < 0 ? "" : "+") << it.x2 << "j" ;
  66. if (it.sz == 3) {
  67. cout << fixed << setprecision(3) << (it.x3 < 0 ? "" : "+") << it.x3 << "k";
  68. }
  69. cout << endl;
  70. }
  71. }
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement