Algorithm increases 6-17 complex arithmetic

Source: Internet
Author: User
Tags stdin

Algorithm increases 6-17 complex arithmetic time limit: 1.0s memory limit: 512.0MBDesign complex number library, realize the basic complex subtraction operation.
Typing only the real and imaginary parts, separated by a space, two complex numbers with operator separation, the output by A+bi format on the screen printing results. Participate in sample input and sample output.
Note In special cases, the output string "error" cannot be computed. Sample Input 2 4 *-3 2 Sample Output -14-8i Sample input 3-2 +-1 3 sample output 2+1i There's a set of data that doesn't work.
#include <iostream>#include<cstdio>#include<vector>#include<queue>#include<cstring>#include<algorithm>#include<cstdlib>#definefor (i,x,n) for (int i=x;i<n;i++)#definell Long Long int#defineINF 0x3f3f3f3f#defineMOD 1000000007#defineMax_n 50005using namespacestd;intMain () {//freopen ("Data.txt", "R", stdin); //freopen ("Data.out", "w", stdout);    Doublea,b,c,d; Charcc; scanf ("%LF%LF",&a,&b);    GetChar (); scanf ("%c",&cc); scanf ("%LF%LF",&c,&d); if(cc=='+'){        if(b+d>0) {printf ("%g+%gi", a+c,b+d); }Else if(b+d<0) {printf ("%g%gi", a+c,b+d); }Else if(b+d==0) {printf ("%g", A +c); }    }    if(cc=='-'){        if(b-d>0) {printf ("%lf+%lfi", a-c,b-d); }Else if(b-d<0) {printf ("%lf%lfi", a-c,b-d); }Else if(b-d==0) {printf ("%LF", A-c); }    }    if(cc=='*'){        if(a*c-b*d==0&&a*d+b*c!=0) {printf ("%gi", a*d+b*c); }Else if(a*d+b*c==0&&a*c+b*d!=0) {printf ("%g", a*c-b*d); }Else{            if(a*d+b*c<0) {printf ("%g%gi", a*c-b*d,a*d+b*c); }Else{printf ("%g+%gi", a*c-b*d,a*d+b*B); }        }    }    if(cc=='/'){        DoubleShi= (a*c+b*d)/(c*c+d*d); Doublexu= (b*c-a*d)/(c*c+d*d); if(c==0&&d==0) {printf ("error\n"); }Else{            if(xu>0) {printf ("%g+%gi", Shi,xu); }            if(xu==0) {printf ("%g", Shi); }Else{printf ("%g%gi", Shi,xu); }        }    }    //fclose (stdin); //fclose (stdout);    return 0;}//3 3 * 3 3

Algorithm increases 6-17 complex arithmetic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.