#39571: C++關於WA (line:1)


singhone0515 (Hugo)

學校 : 國立新營高級中學
編號 : 196294
來源 : [101.9.64.52]
最後登入時間 :
2024-04-28 12:27:12
a017. 五則運算 | From: [36.237.151.76] | 發表日期 : 2024-03-07 01:31

#include<bits/stdc++.h>
using namespace std;
#define int long long
string str;
int i;
 
int func(){
stack<int> s;
char tbl[10];
int num,tmp;
char type='+';
while(1){
for(int i=0;i<10;i++) tbl[i]='\0';
for(i,tmp=0;i<str.size();i++){
if(tmp!=0 && str[i]==' ') break;
else if(str[i]!=' ') tbl[tmp++]=str[i];
}
if(tbl[0]=='!'){
int total=0;
while(!s.empty()){
total+=s.top();
s.pop();
}
return total;
}
 
if(tbl[0]=='('){
num=func();
switch(type){
case '+':
s.push(num);
break;
case '-':
s.push(-num);
break;
case '*':
num*=s.top();
s.pop();
s.push(num);
break;
case '/':
num/=s.top();
s.pop();
s.push(num);
break;
case '%':
num%=s.top();
s.pop();
s.push(num);
break;
}
}
else if(tbl[0]==')'){
int total=0;
while(!s.empty()){
total+=s.top();
s.pop();
}
return total;
}
else if(tbl[0]=='*' || tbl[0]=='/' || tbl[0]=='%' || tbl[0]=='-' || tbl[0]=='+'){
type=tbl[0];
}
else{
num=atoi(tbl);
switch(type){
case '+':
s.push(num);
break;
case '-':
s.push(-num);
break;
case '*':
num*=s.top();
s.pop();
s.push(num);
break;
case '/':
num/=s.top();
s.pop();
s.push(num);
break;
case '%':
num%=s.top();
s.pop();
s.push(num);
break;
}
}
}
}
 
signed main(){
int ans;
while(getline(cin,str)){
i=0;
str+=" !";
ans=func();
printf("%lld\n",ans);
}
}

測試AC 送出解答卻WA(line:1)

不知道哪邊有錯,有沒有人可以救我QAQ

測試AC, 送出解答卻 WA (line:1)

 
#39575: Re: C++關於WA (line:1)


singhone0515 (Hugo)

學校 : 國立新營高級中學
編號 : 196294
來源 : [101.9.64.52]
最後登入時間 :
2024-04-28 12:27:12
a017. 五則運算 | From: [101.9.100.220] | 發表日期 : 2024-03-07 10:57

a/b寫成b/a. :)

搞了我自己好久

 
ZeroJudge Forum