http://ac.jobdu.com/problem.php?pid=1103 二次方程计算器

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;int main(void)
{int i,index,a,b,c,m,sign,ra,rb,rc;char str[200];double rt,first,second;while(scanf("%s",str)!=EOF){for(i=0;str[i]!='\0';i++){if(str[i]=='='){index=i;break;}}a=b=c=0;m=0,sign=1;for(i=0;i<index;)    //方程等式的左半部分{if(str[i]>='0' && str[i]<='9'){m=m*10+str[i]-'0';i++;}else if(str[i]!='x'){if(str[i]=='+'){c+=m*sign;sign=1;}else if(str[i]=='-'){c+=m*sign;sign=-1;}i++;m=0;}else if(str[i]=='x' && str[i+1]=='^'){if(i==0 || str[i-1]=='+' || str[i-1]=='-')m=1;a+=m*sign;m=0;i=i+3;}else if(str[i]=='x' && str[i+1]!='^'){if(i==0 || str[i-1]=='+' || str[i-1]=='-')m=1;b+=m*sign;m=0;i++;}}//forc+=m*sign;ra=rb=rc=0;m=0,sign=1;for(i=index+1;str[i]!='\0';)    //方程等式的右半部分{if(str[i]>='0' && str[i]<='9'){m=m*10+str[i]-'0';i++;}else if(str[i]!='x'){if(str[i]=='+'){rc+=m*sign;sign=1;}else if(str[i]=='-'){rc+=m*sign;sign=-1;}i++;m=0;}else if(str[i]=='x' && str[i+1]=='^'){if(i==index+1 || str[i-1]=='+' || str[i-1]=='-')m=1;ra+=m*sign;m=0;i=i+3;}else if(str[i]=='x' && str[i+1]!='^'){if(i==index+1 || str[i-1]=='+' || str[i-1]=='-')m=1;rb+=m*sign;m=0;i++;}}//forrc+=m*sign;a-=ra;b-=rb;c-=rc;if(b*b-4*a*c>=0){rt=sqrt(1.0*b*b-4*a*c);if(a>0){first=(-b-rt)/(2*a);second=(-b+rt)/(2*a);}else{first=(b+rt)/(-2*a);second=(b-rt)/(-2*a);}if(first<second)printf("%.2lf %.2lf\n",first,second);elseprintf("%.2lf %.2lf\n",second,first);}elseprintf("No Solution\n");}return 0;
}// 3x+4=x^2+x
// -x^2=0

2011年上海交通大学计算机研究生机试真题相关推荐

  1. 上海交大研究生计算机考研真题,2011年上海交通大学计算机研究生机试真题

    Oracle 约束(constraint)的几个参数的小研究 ORACLE中,约束分deferred 跟 immediate 2种: deferred:如果 Oracle 在事务提交(commit)时 ...

  2. 211大学计算机复试不机试,复试机试之上海交通大学计算机研究生机试真题.doc...

    复试机试之上海交通大学计算机研究生机试真题 (你自己回去改格式啊,这个有多重繁杂字体,你自己改好看点~~还有知识05年到11年的)复试机试之2011年上海交通大学计算机研究生机试真题 (2012-02 ...

  3. 2005年上海交通大学计算机研究生机试真题

    http://ac.jobdu.com/problem.php?pid=1090   路径打印 #include<iostream> #include<set> #includ ...

  4. 2006年上海交通大学计算机研究生机试真题

    http://ac.jobdu.com/problem.php?pid=1095 2的幂次方 //手动模拟 #include<iostream> #include<string> ...

  5. 最大公约数 [2011年哈尔滨工业大学计算机研究生机试真题]

    题目描述> 输入两个正整数,求其最大公约数. 输入描述: 测试数据有多组,每组输入两个正整数. 输出描述: 对于每组输入,请输出其最大公约数. 样例输入: 49 14 样例输出: 7 解题思路: ...

  6. 2000年华中科技大学计算机研究生机试真题 对称矩阵

    题目1180:对称矩阵 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2518 解决:1295 题目描述: 输入一个N维矩阵,判断是否对称. 输入: 输入第一行包括一个数:N(1<= ...

  7. 2011年北京大学计算机研究生机试真题(dijkstra+优先队列)

    http://ac.jobdu.com/problem.php?pid=1162  I Wanna Go Home 方法一:普通的dijkstra /* 很明显的最短路,但关键是如何建图.可以看到,一 ...

  8. 2011年吉林大学计算机研究生机试真题

    http://ac.jobdu.com/problem.php?pid=1107     搬水果 方法一:(优先队列) #include<iostream> #include<que ...

  9. 2008--2009年北京航空航天大学计算机研究生机试真题

    http://ac.jobdu.com/problem.php?pid=1165 字符串匹配 #include<iostream> #include<cstdio> #incl ...

最新文章

  1. Windows 下连接mysql工具NavicatForMysql
  2. git 常用命令以及其他使用笔记
  3. Nginx配置SSL后不能正常访问解决方法
  4. 1.8 编程基础之多维数组 08 矩阵加法 python
  5. Javascript——Math对象
  6. html5用户注册页面代码,HTML5注册页面示例代码
  7. 读《未来世界的幸存者》
  8. Lucene倒排索引简述 番外篇
  9. 编译原理实验二:词法分析程序
  10. 什么是嵌入式操作系统?
  11. Jmeter断言-所有断言讲解
  12. Arduino开发教程汇总
  13. Maya 更改模型枢轴位置 Day1
  14. 给即将入职的师弟师妹的建议:去看看这个世界
  15. Android 开发:由模块化到组件化(一)
  16. DM8060驱动器的使用
  17. pyqt5-weidget-鼠标操作(鼠标形状、鼠标跟踪,QCursor)
  18. system32下的文件
  19. 使用python进行傅里叶FFT 频谱分析
  20. 手把手教学php表情包,手把手教你爬取斗图啦表情包

热门文章

  1. P1111 修复公路(并查集)
  2. 皇nity webgl与html交互文件,Vue与UnityWebGl交互通信
  3. 阿里云携手晞司盖工业,赋能设备制造商制造+服务转型升级
  4. 2021阿里巴巴研发效能峰会来啦!
  5. 入门顶点动画纹理的实例化绘制
  6. 软件的Express Edition是什么版?
  7. ORA-39095: Dump file space has been exhausted: Unable to allocate 8192 bytes
  8. BZOJ2442: [Usaco2011 Open]修剪草坪 单调队列优化dp
  9. 5.linux目录结构介绍
  10. CSS精灵图合成工具