程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i = 0, sum=0, flag=0, j=0;
char str[20] = { 0 };
scanf("%s", str);
while (!(str[i] >= '0' && str[i] <= '9')) i++;
sum += str[i] - 48;
if (i == strlen(str))
{
return sum;
}
i += 1;
for (j = i;j<strlen(str);j++)
{
if ( str[j]>= '0' && str[j]<= '9')
{
flag++;
switch (flag % 3)
{
case 1:
sum += str[j] - 48;
break;
case 2:
sum -= (str[j] - 48);
break;
case 0:
sum *= (str[j] - 48);
break;
}
}
}
printf("%d", sum);
system("pause");
return 0;
}