# NYOJ128（测试数据提示）

NYOJ 128

测了很长时间，一直runtime error。。才发现是数据输入的问题没有考虑完全

若数据之间有空格 ，你是否处理了？

#include<cstdio>
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;

double stnum[501];

int top = 0;
void Calculation(char str)
{
double a,b;
a = stnum[--top] ;

b = stnum[--top];

switch(str )
{
case '+': stnum[top++] = (a+b);break;
case '-': stnum[top++] =(a-b);break;
case '*': stnum[top++] =(a*b);break;
case '/': stnum[top++] =(a/b);break;

}

}

int main()
{
int n,len,i;
char str[10000],c;
double sum1,sum2,j;

while(gets(str)!=NULL)
{
top = 0;
len = strlen(str);
for(i=len -1 ; i>=0 ;)
{
if(str[i] >= '0' && str[i] <= '9')
{
sum1 =0;j= 1;
while(i>=0 && str[i] >= '0' && str[i] <= '9')
{
sum1 += (str[i] - '0')*j;
j*=10;
i--;
}
if(i>=0 && str[i] == '.')
{
sum1 = (sum1)/j;
sum2 = 0;i--;j = 1;
while(i>=0 && str[i] >= '0' && str[i] <= '9')
{
sum2 += (str[i] - '0')*j;
j*=10;
i--;
}
sum1 += sum2  ;
}
//	printf("sum1-->%lf \n",sum1);
stnum[top++] = sum1;

}
else if(str[i] == ' ') //多空格处理的
{
i--;
}
else
{
Calculation(str[i]);
i--;
}

}
printf("%.2lf\n",stnum[0]);
top--;

}
return 0;
}

#include<stdio.h>

#include<string.h>

double stnum[1000];
//stack <char> ststr;
int top = 0;
void Calculation(char str)
{
double a,b;
a = stnum[--top] ;

b = stnum[--top];

switch(str )
{
case '+': stnum[top++] = (a+b);break;
case '-': stnum[top++] =(a-b);break;
case '*': stnum[top++] =(a*b);break;
case '/': stnum[top++] =(a/b);break;

}

}

int main()
{
int n,len,i;
char str[1010],c;
double sum1,j;

while(gets(str)!= NULL)
{
top = 0;
len = strlen(str);
for(i=len -1 ; i>=0 ;)
{
if(str[i] >= '0' && str[i] <= '9')
{
while(i>=0 && str[i] >= '0' && str[i] <= '9')
{
i--;
}
if(str[i] == '.')
{
i--;
while(i>=0 && str[i] >= '0' && str[i] <= '9')
{
i--;
}
}
i++;
//printf("i-->%d\n",i);
sscanf(&str[i],"%lf",&sum1);
stnum[top++] = sum1;
i--;
}
else if(str[i] == ' ')
{
i--;
}
else
{
Calculation(str[i]);
i--;
}

}
printf("%.2lf\n",stnum[0]);

}
return 0;
}