-
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