fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int main()
  6. {
  7. int i, j, T, a[3], d;
  8. char Buffer[64], Expression[64], *ptr;
  9. scanf("%d",&T);
  10. gets(Buffer); // to ignore enter press after T input.
  11.  
  12. while(T--)
  13. {
  14. gets(Buffer);
  15. for(i=j=0; Buffer[i]!='='; i++)
  16. {
  17. if(Buffer[i]==' ') continue;
  18. if(Buffer[i]=='-' || Buffer[i]=='+')
  19. {
  20. Expression[j++] = ' '; Expression[j++] = Buffer[i];
  21. }
  22. else Expression[j++] = Buffer[i];
  23. }
  24. Expression[j] = 0;
  25. ptr = strtok(Expression, " ");
  26. a[0] = a[1] = a[2] = 0;
  27. while(ptr)
  28. {
  29. for(i=j=0; ptr[j]; j++) i += (ptr[j]=='x');
  30. a[i] = atoi(ptr);
  31. if(!a[i]) a[i] = ptr[0]=='-'?-1:1;
  32. ptr = strtok(0, " ");
  33. }
  34. d = a[1]*a[1] - 4*a[2]*a[0];
  35. if(!d) puts("Equal roots.");
  36. else if(d < 0) puts("Imaginary roots.");
  37. else puts("Distinct real roots.");
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 1836KB
stdin
2
x*x-2*x+1=0
2*x*x+5*x-3=0
stdout
Equal roots.
Distinct real roots.