当前位置:首页 > 浙江大学计算机学院考研复试上机试题及参考答案
num1 = 0; breakflag = 1; p = strtok(op1,\ while(p) /* 求出第一个输入火星数的数组 */ {
if( ( op1List[num1++] = atoi(p) ) != 0) breakflag = 0; p = strtok(NULL,\ }
if(breakflag) break; /* 第一个输入为0,退出循环;如果放到ZOJ2529,删除本行 */
num2 = 0; breakflag = 1; p = strtok(op2,\ while(p) /* 求出第二个输入火星数的数组 */ {
if( ( op2List[num2++] = atoi(p) ) != 0) breakflag =0;
p = strtok(NULL,\ }
if(breakflag) break; /* 第二个输入为0,退出循环;如果放到ZOJ2529,删除本行 */
num1--,num2--; /* preset num1 and num2 start from zero */
if(num1 < num2) /* 把输入的两个火星数数按位序对齐,两个if操作只执行一个 */
for(i = num1; i >= 0; --i) {
op1List[i + num2 - num1] = op1List[i]; op1List[i] = 0; }
if(num1 > num2)
for(i = num2; i >= 0; --i) {
op2List[ i + num1 - num2] = op2List[i]; op2List[i] = 0; }
cnt = (num1 > num2) ? num1 : num2; /* cnt为两个火星数的较大位数,便于确定输出位数 */
for( index=0, i=cnt; i>=0 ; i--, index++ ) {
num = op1List[i] + op2List[i] + OutputList[index];
if( num - PrimeList[index] >= 0 ) {
OutputList[index] = num - PrimeList[index]; OutputList[index+1]++;
if( index + 1 > cnt ) cnt++; /* 最高位进位 */ } else
OutputList[index] = num; }
while( OutputList[cnt]==0 && cnt ) cnt--; /* omit leading zeros */ for( ; cnt >=0 ; cnt-- )
printf(\(cnt==0)?'\\n':','); }while(1); return 0; }
?
2006年浙江大学计算机学院考研复试上机试题及参考答案(4/5) 第4题:简单计算器(7分)
题目要求:读入一个只包含 +, -, *, / 的正整数计算表达式,计算该表达式的值。
输入格式:测试输入包含若干测试用例,每个测试用例占一行,每行不超过80个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。
输出格式:对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。 输入样例: 1 + 2
4 + 2 * 5 - 7 / 11 0
输出样例: 3.00 13.36
#include
共分享92篇相关文档