0
1
已采纳
那乘法呢?
所以要在第3行加一个long long jc=1;
删除第8行,改成:
if(zf=='乘号'){
jc*=a;
}
if(zf==‘加号){
sum+=a;
}
其它不改。
注意看题啊,别粗心!!!
0
@李子杰 为啥我的代码和你差不多,还是WA
#include <bits/stdc++.h>
using namespace std;
int main(){
int a=1;
long long with=0,product=1;
char zf;
cin>>zf;
while(a!=0){
cin>>a;
if(zf=='+'){
with+=a;
}
if(zf=='*'){
product*=a;
}
}
if(zf=='+'){
cout<<with;
}
else if(zf=='*'){
cout<<product;
}
return 0;
}
0
0
0
long long a,m,sum,s=1,cnt;
char n;
cin>>n;
while(1){
cin>>a;
if(a==0){
break;
}
if(n=='+'){
sum+=a;
}else{
s*=a;
}
}
if(n=='+'){
cout<<sum<<endl;
}
else
cout<<s<<endl;
0

