私は問題解決に不慣れです。そして、私はエクスプレッションと呼ばれるUVAの問題を解決していました。私のコードはすべての可能なテストケースに対して正しい出力を提供するので、私は問題を解決したと思います。しかし、それでも私はWAを取得しています。どこかで正しく行っていない改行を印刷したようです。この問題は、「出力ファイルには、各接尾辞式がすべて1行に含まれます。異なる式の間に空白行を出力します」というものです。誰かが私にこれを少しはっきりと説明してもらえますか?グループで質問しましたが、回答がありません。そして、以前の議論も役に立たなかった。前もって感謝します。
#include<iostream>
#include<map>
#include<stack>
#include<vector>
#include<cstdio>
using namespace std;
void push_into_stack(char c, vector< char > &ans, stack< char > &st);
void work_with_stack(vector< char > &ans, stack< char > &st);
int main(void)
{
freopen("input.txt", "r", stdin);
int t;
char dummy;
cin >> t;
for(int i=1; i<=t; i++)
{
vector< char > exp, ans;
stack< char > st;
char c;
while(cin >> c)
exp.push_back(c);
for(int i=0; i<exp.size(); i++)
if(exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/') push_into_stack(exp[i], ans, st);
else if(exp[i]=='(') st.push(exp[i]);
else if(exp[i]==')') work_with_stack(ans, st);
else ans.push_back(exp[i]);
while(!st.empty())
{
ans.push_back(st.top());
st.pop();
}
for(int i=0; i<ans.size(); i++)
cout << ans[i];
cout << endl;
}
return 0;
}
void push_into_stack(char c, vector< char > &ans, stack< char > &st)
{
map< char, int > mp;
mp['/']=2;
mp['*']=2;
mp['+']=1;
mp['-']=1;
while(true)
{
if(!st.empty() && mp[c]<=mp[st.top()])
{
ans.push_back(st.top());
st.pop();
}
else
{
st.push(c);
break;
}
}
return;
}
void work_with_stack(vector< char > &ans, stack< char > &st)
{
while(true)
{
if(st.top()=='(') break;
ans.push_back(st.top());
st.pop();
}
st.pop();
return;
}