hdu 1237 简单计算器

来源:互联网 发布:山东博达网络 编辑:程序博客网 时间:2024/05/16 09:12

http://acm.hdu.edu.cn/showproblem.php?pid=1237

分析:看来对栈的应用还是不熟练,汗颜啊

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){double s[205],t;char f;int i,j;while( cin >> t ){f=getchar( );if( f == '\n' && t == 0 ) //break;memset( s,0,sizeof(s) );s[0] = t;i=0;while( 1 ){cin >> f >> t;if( f == '*' )  s[i] *= t;else if( f == '/' )  s[i] /= t;else if( f == '+' ) s[++i] = t;else s[++i] = -t;if( getchar( ) == '\n' )break;}t=0.0;for( j = 0;j <= i;j++ )t += s[j];printf( "%.2lf\n",t );}return 0;}


原创粉丝点击