fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. struct sphuc
  5. {
  6. double thuc, ao;
  7. };
  8.  
  9. void in(sphuc x)
  10. {
  11. if(x.thuc == 0)
  12. {
  13. if(x.ao == 0) cout << 0 << "\n";
  14. else if(x.ao == 1) cout << "i" << "\n";
  15. else if(x.ao == -1) cout << "-i" << "\n";
  16. else cout << x.ao << "i" << "\n";
  17. }
  18. else
  19. {
  20. if(x.ao == 0) cout << x.thuc << "\n";
  21. else if(x.ao == 1) cout << x.thuc << " + i" << "\n";
  22. else if(x.ao == -1) cout << x.thuc << " - i" << "\n";
  23. else if(x.ao > 1) cout << x.thuc << " + " << x.ao << "i\n";
  24. else if(x.ao < -1) cout << x.thuc << " - " << fabs(x.ao) << "i\n";
  25. }
  26. }
  27.  
  28. sphuc cong(sphuc x, sphuc y)
  29. {
  30. sphuc s;
  31. s.thuc = x.thuc + y.thuc;
  32. s.ao = x.ao + y.ao;
  33. return s;
  34. }
  35.  
  36. sphuc tru(sphuc x, sphuc y)
  37. {
  38. sphuc s;
  39. s.thuc = x.thuc - y.thuc;
  40. s.ao = x.ao - y.ao;
  41. return s;
  42. }
  43.  
  44. sphuc nhan(sphuc x, sphuc y)
  45. {
  46. sphuc s;
  47. s.thuc = x.thuc*y.thuc - x.ao*y.ao;
  48. s.ao = x.thuc*y.ao + x.ao*y.thuc;
  49. return s;
  50. }
  51.  
  52. int main() {
  53. int t; cin >> t;
  54. while(t--)
  55. {
  56. sphuc a, b;
  57. cin >> a.thuc >> a.ao >> b.thuc >> b.ao;
  58. in(cong(a,b));
  59. in(tru(a,b));
  60. in(nhan(a,b));
  61. }
  62. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty