{
  "question_id": 229922,
  "question_title": "求解一元二次方程组根问题",
  "question_content": "<pre>利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b - sqrt(b*b-4*a*c))/(2*a)求一元二次方程ax<sup>2</sup> + bx + c =0 的根，其中a不等于0。\n输入一行，包含三个浮点数a, b, c（它们之间以一个空格分开），分别表示方程ax<sup>2</sup> + bx + c =0 的系数。输出一行，表示方程的解。\n若两个实根相等，则输出形式为：x1=x2=...。\n若两个实根不等，则输出形式为：x1=...;x2 = ...，其中x1若是两个虚根，则输出：x1=实部+虚部i; x2=实部-虚部i，其中x1,x2满足以下两个条件中的一个：\n1. x1的实部大于x2的实部\n2. x1的实部等于x2的实部且x1的虚部大于等于x2的虚部\n所有实数部分要求精确到小数点后5位，数字、符号之间没有空格。\n样例输入：1.0 2.0 8.0\n样例输出：x1=-1.00000+2.64575i;x2=-1.00000-2.64575i</pre>",
  "difficulty": "困难",
  "answer_id": 198570,
  "answer_content": "\n\n```\n #include <iostream>\n#include<iomanip>\n#include <cmath>\n#include <complex>\nusing namespace std;\nstatic const double e = 1e-12;\nbool operator == (complex<double> c1, complex<double> c2) { return abs(c1-c2) < e;}\nint main()\n{\n    complex<double> a,b,c;\n    complex<double> x1,x2;\n    cin >> a >> b >> c;\n    x1 = (-b + sqrt(b*b-a*c*4.0))/(a*2.0);\n    x2 = (-b - sqrt(b*b-a*c*4.0))/(a*2.0);\n    cout << setiosflags(ios::fixed);\n    cout.precision(6);\n    if ( abs(x1.imag()) < e )   // real\n    {\n        if (x1 == x2) {\n            cout << \"x1=x2=\" << x1.real();\n        } else  {\n            cout << \"x1=\" << x1.real() <<\";x2=\" << x1.real();\n        }\n    }\n    else {\n        cout << \"x1=\" << x1.real()<<\"+\"<<x1.imag()<<\"i;\"\n                <<\"x2=\" << x2.real()<<\"+\"<<x2.imag()<<\"i\";\n    }\n    return 0;\n}\n```\n\n",
  "tag_name": "c++",
  "cpp": "#include <iostream>\n#include<iomanip>\n#include <cmath>\n#include <complex>\nusing namespace std;\nstatic const double e = 1e-12;\nbool operator == (complex<double> c1, complex<double> c2) { return abs(c1-c2) < e;}\nint main()\n{\n\tcomplex<double> a,b,c;\n\tcomplex<double> x1,x2;\n\tcin >> a >> b >> c;\n\tx1 = (-b + sqrt(b*b-a*c*4.0))/(a*2.0);\n\tx2 = (-b - sqrt(b*b-a*c*4.0))/(a*2.0);\n\tcout << setiosflags(ios::fixed);\n\tcout.precision(6);\n\tif ( abs(x1.imag()) < e )   \n\t{\n\t\tif (x1 == x2) {\n\t\t\tcout << \"x1=x2=\" << x1.real();\n\t\t} else  {\n\t\t\tcout << \"x1=\" << x1.real() <<\";x2=\" << x1.real();\n\t\t}\n\t}\n\telse {\n\t\tcout << \"x1=\" << x1.real()<<\"+\"<<x1.imag()<<\"i;\"\n\t\t\t\t<<\"x2=\" << x2.real()<<\"+\"<<x2.imag()<<\"i\";\n\t}\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470279",
  "status": 1,
  "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/141.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "goddnessblesser"
}