算是转移题
考虑可以交换次序的情况:连续的加法运算,或者乘法运算可以交换
(但是提交只过了27%,可能情况考虑的不周全)
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int *a=new int[n];
char *b=new char[n-1];
for(int i=0;i<n-1;i++)
{
cin>>a[i];
cin>>b[i];
}
cin>>a[n-1];
for (int i=0;i<n-1;i++)
{
for (int i=0;i<n-1;i++)
{
if (b[i]=='+'&&(b[i+1]=='+'))
{
if (a[i]>a[i+1])
{
int t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
if (b[i]=='*')
{
if (a[i]>a[i+1])
{
int t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
}
for (int i=0;i<n-1;i++)
{
cout<<a[i]<<" ";
cout<<b[i]<<" ";
}
cout<<a[n-1]<<endl;
return 0;
}