代码:
#include<bits/stdc++.h>
using namespace std;
struct ine
{
int val;
bool isg,eq;
};
struct cmp
{
bool operator()(ine x,ine y)
{
if (x.val!=y.val)return x.val>y.val;
if (x.isg!=y.isg)return !x.isg;
if (x.isg)return !x.eq;
return x.eq;
}
};
priority_queue<ine,vector<ine>,cmp >q;
int n,sval,gval;
bool seq,geq;
char c;
string s;
int main()
{
cin>>n>>c;
for (int i=0;i<n;i++)
{
ine t;
t.val=0;
cin>>s;
int sz=s.size(),now=2;
bool negative=0;
if (s[1]=='>')t.isg=1;
else t.isg=0;
if (s[2]=='=')
{
t.eq=1;
now=3;
}
else t.eq=0;
if (s[now]=='-')
{
now++;
negative=1;
}
for (;now<sz;now++)t.val=t.val*10+s[now]-'0';
if (negative)t.val*=-1;
q.push(t);
}
bool smaller=0,isg=0;
while (!q.empty())
{
ine t=q.top();
q.pop();
if (!t.isg)
{
if (!smaller)
{
if (t.eq)geq=1;
gval=t.val;
}
smaller=1;
}
else if (smaller)
{
cout<<"No Answer!";
return 0;
}
else
{
isg=1;
if (t.eq)seq=1;
else seq=0;
sval=t.val;
}
}
if (sval==gval)
{
if (seq&&geq)cout<<c<<'='<<sval;
else cout<<"No Answer!";
return 0;
}
if (!isg)
{
cout<<c<<'<';
if (geq)cout<<'=';
cout<<gval;
return 0;
}
if (!smaller)
{
cout<<c<<'>';
if (seq)cout<<'=';
cout<<sval;
return 0;
}
cout<<sval<<'<';
if (seq)cout<<'=';
cout<<c;
cout<<'<';
if (geq)cout<<'=';
cout<<gval;
}
知道问题在哪里的大佬请 @HuangRuibo 谢谢