35分求助
查看原帖
35分求助
1022630
cola_01楼主2024/9/4 11:21

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,op1,op2,minn=LONG_LONG_MAX,maxn=LONG_LONG_MIN;
char x;
signed main()
{
	cin >> n >> x;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin >> s;
		string s1,s2;
		s1+=s[1]; 
		if(s[2]=='=')s1+='=',s2=s.substr(3);
		else s2=s.substr(2);
		if(s1[0]=='>')
		{
			if(maxn<stoll(s2))
			{
				maxn=stoll(s2);
				if(s1==">=") op1=4;
				else op1=3;
			}
		}
		else
		{
			if(minn>stoll(s2))
			{
				minn=stoll(s2);
				if(s1=="<=") op2=4;
				else op2=3;
			}
		}
	}
	if(minn<maxn&&op1>0&&op2>0) cout << "No Answer!";
	else 
	{
		if(op1>0&&op2==0)
		{
			cout << x;
			if(op1==4) cout << ">=";
			else cout << ">";
			cout << maxn;
		}
		else if(op2>0&&op1==0)
		{
			cout << x;
			if(op2==4) cout << "<=";
			else cout << "<";
			cout << minn;
		} 
		else{
			cout << maxn;
			if(op1==4) cout << "<=";
			else cout << "<";
			cout << x;
			if(op2==4) cout << "<=";
			else cout << "<";
			cout << minn;
		}
		
	}
	return 0;
}
2024/9/4 11:21
加载中...