#include<iostream>
#include<cstdio>
using namespace std;
int a[1001];
int main()
{
int n,x,y,max=0,M=1e9,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x>>y;
a[x]=(a[x]<y?y:a[x]);
max=(max<x?x:max);
}
for(int i=max;i>=1;i--)
{
//cout<<s<<" "<<M<<" "<<i<<" "<<a[i]<<" "<<(a[i]!=0)<<"&&"<<(M>a[i])<<endl; 这里是调试用的
if(a[i]!=0 && M>a[i])
{
if(s=0)
{
s=1;
}
else
{
cout<<",";
}
cout<<"("<<i<<","<<a[i]<<")";
M=a[i];
}
}
}
/*
5
1 2 2 2 3 1 2 3 1 4
*/
问题:不知道哪里错了,就是不对
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=105;
struct coord
{
int x,y,z;
}c[maxn];
bool cmp(struct coord a,struct coord b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
bool comp(struct coord a,struct coord b)
{
if(a.z==1&&b.z==1) return a.x<b.x;
else return a.x<b.x;
}
int main()
{
int n,he;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>c[i].x>>c[i].y;
c[i].z=0;
}
sort(c,c+n,cmp);
c[n-1].z=1;//最后一个肯定是极大值点
he=c[n-1].y;
for(int i=n-2;i>=0;i--)
{
if(c[i].y>he)//x越小,y应该越大
{
he=c[i].y;
c[i].z=1;
}
}
sort(c,c+n,comp);//x从小到达输出
bool first=true;
for(int i=0;i<n;i++)
{
if(c[i].z)
{
if(first)
{
printf("(%d,%d)",c[i].x,c[i].y);
first=false;
}
else printf(",(%d,%d)",c[i].x,c[i].y);
}
}
return 0;
}
应该是 if (s == 0)
你写的一个 赋值 s = 0,这个是恒成立的