初学者,不知道哪有问题,tle了俩。求佬看看
查看原帖
初学者,不知道哪有问题,tle了俩。求佬看看
1111121
pengyuyancdu楼主2023/11/24 00:28
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct yy
{
	int s;
	char p[101];
}yyy[21];
bool cmp(yy a,yy b)
{
	int i1=strlen(a.p);
	int i2=strlen(b.p);
	int l=i1;
	if(i1>i2)return 1;
	else if(i2>i1)return 0;
	for(int i=0;i<l;l++)
	{
		if(a.p[i]>b.p[i])return 1;
		else if(a.p[i]<b.p[i])return 0;
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		yyy[i].s=i;
		cin>>yyy[i].p;
	}
	sort(yyy+1,yyy+1+n,cmp);
	cout<<yyy[1].s<<endl<<yyy[1].p;
	return 0;
}
2023/11/24 00:28
加载中...