Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Vec {
- public:
- double x1, x2, x3;
- int sz = 0;
- Vec(double x1, double x2, double x3) {
- this->x1 = x1;
- this->x2 = x2;
- this->x3 = x3;
- }
- double module() {
- return (sqrt(x1*x1 + x2*x2 +x3*x3));
- }
- };
- vector<Vec> V;
- Vec parse(string s) {
- std::string delimiter = ";";
- s = s + delimiter;
- size_t pos = 0;
- std::string token;
- int position = 0;
- std::string::size_type sz;
- Vec rs = Vec(0,0,0);
- while ((pos = s.find(delimiter)) != std::string::npos) {
- token = s.substr(0, pos);
- double x = stod(token, &sz);
- //cout << x << endl;
- if ( position == 0 ){
- rs.x1 = x;
- } else if (position == 1) {
- rs.x2 = x;
- } else {
- rs.x3 = x;
- }
- s.erase(0, pos + delimiter.length());
- position++;
- }
- rs.sz = position;
- return rs;
- }
- int main(){
- ifstream cin("test.in");
- for (string s; cin >> s;) {
- V.push_back(parse(s));
- }
- Vec sum = Vec(0,0,0);
- for (auto it: V) {
- sum.x1 += it.x1;
- sum.x2 += it.x2;
- sum.x3 += it.x3;
- }
- for (auto it: V) {
- if (it.module() >= sum.module()) {
- cout << fixed << setprecision(3) << (it.x1 < 0 ? "" : "") << it.x1 << "i"<<(it.x2 < 0 ? "" : "+") << it.x2 << "j" ;
- if (it.sz == 3) {
- cout << fixed << setprecision(3) << (it.x3 < 0 ? "" : "+") << it.x3 << "k";
- }
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement