Nine degrees OJ topic 1103: Two-time equation calculator

Source: Internet
Author: User

Title Description:

Design a two-time equation calculator

Input:

Each case is a two-time equation of expression for x, and for simplicity, each coefficient is an integer form.

Output:

Each case outputs two real numbers (from small to large output, separated by spaces), retains two decimal places, and outputs "no solution" if no solution is provided.

Sample input:
X^2+x=3x+4
Sample output:
-1.24 3.24
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <cmath>6 #defineMAX 1027 8 CharEr[max];9 intMainintargcChar Const*argv[])Ten { One     intN, M, K; A     //freopen ("Input.txt", "R", stdin); -      while(SCANF ("%s", er)! =EOF) { -        intA =0, B =0, C =0; the        intState =1; -        inti =0; -        inttemp =1; -        intFu =1; +         while(I <strlen (er)) { -             if(Er[i] = ='x'&& i+2<strlen (er)) { +                 if(er[i+1] =='^'&& er[i+2] =='2') { Atemp = temp *Fu; atA = a +temp; -i = i +3; -temp =State ; -                 } -                 Else { -temp = temp *Fu; inB = B +temp; -i++; totemp =State ; +                 } -             } the             Else if(Er[i] = ='x') { *temp = temp *Fu; $B = B +temp;Panax Notoginsengi++; -temp =State ; the             } +             Else if(Er[i] = ='-') { AFu =-1; thei++;  +             } -             Else if(Er[i] = ='+') { $Fu =1; $i++;  -             } -             Else if(Er[i] >='0'&& Er[i] <='9') { thetemp =0; -                  while(Er[i] >='0'&& Er[i] <='9') {Wuyitemp = temp *Ten+ Er[i]-'0'; thei++; -                 } Wutemp = temp *State ; -                 if((I < strlen (er) && er[i]! ='x') || i = =strlen (er)) { Abouttemp = temp *Fu; $c = C +temp; -temp =State ; -                 } -             } A             Else if(Er[i] = ='=') { +State =-1; thetemp =State ; -Fu =1; $i++; the             } the        } the        //printf ("%d%d%d\n", a,b,c); the        Doubleat = a, BT = b, ct =C; -        DoubleAnsa, ANSB; in        DoubleDT = bt*bt-4*at*CT; the        if(DT <0) { thePuts"No Solution"); About        } the        Else { theAnsa = (-bt-sqrt (DT))/(2*At ); theANSB = (-bt + sqrt (dt))/(2*At ); +printf"%.2LF%.2lf\n", Ansa, ANSB); -        } the     }Bayi     return 0; the}

Nine degrees OJ topic 1103: Two-time equation calculator

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.