ArioKings @ 2024-05-06 22:52:34
我在输入第一个案例的时候,计算9+7会变成9+10,这是为什么?求解答
#include <cstdio>
using namespace std;
int main() {
char str[51];
long long num[50] = {0};
scanf("%s",str);
int i = 0,j = 0;
while(str[i] != '@') {
if(str[i] >= '0' && str[i] <= '9') {
num[j] += (long long)(str[i] - '0');
if(str[i+1] != '.')
num[j] *= 10;
}
else {
switch(str[i]) {
case '.':
j ++;
break;
case '+':
num[j-2] = num[j-2] + num[j-1];
j --;
break;
case'-':
num[j-2] = num[j-2] - num[j-1];
j --;
break;
case'*':
num[j-2] = num[j-2] * num[j-1];
j --;
break;
case'/':
num[j-2] = num[j-2] / num[j-1];
j --;
break;
}
}
i ++;
}
printf("%ld",num[0]);
}
by Poker11037 @ 2024-05-17 21:41:22
@ArioKings 虽然但是哥们,你这单引号框出问题了,下面绿花花一片(