📄 operator.cpp
字号:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.H>
#include <string.h>
void Ready(char * str)
{
scanf("%s", &str[1]);
str[0] = '(';
str[strlen(str)] = ')';
}
double CalStr(char * str)
{
double result;
int flag = 0;
if ( isdigit(*str))
{
result = atol(str);
while ( isdigit(*str)) *(str++) = '#';
}
else
{
if ( *str == '-') result = -CalStr(str+1);
else result = CalStr(str+1);
if ( *str == '(' ) flag = 1;
*str = '#';
while ( *str == '#' ) str++;
while ( *str != ')')
{
switch(*str)
{
case '*': result *= CalStr(str+1); break;
case '/': result /= CalStr(str+1); break;
default: result += CalStr(str); break;
}
*str = '#';
while ( *str == '#') str++;
}
if ( flag == 1 ) *str = '#';
}
return result;
}
void main()
{
char str[100];
Ready(str);
printf("\nthe result is %lf\n", CalStr(str));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -