本题我最初死在那个标号搞不清楚,不会求——QWQ
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int flag;
bool cmp(string a,string b)//数组没必要标记
{
if(a.length()!=b.length()) return a.length()>b.length();
for(int i=0;i<a.length();i++)
{
if(a[i]==b[i])continue;
else
{
return a[i]>b[i];
break;
}
}
}
int main()
{
string num[101];
int n;scanf("%d",&n);
for(int i=0;i<n;i++)cin>>num[i];
sort(num,num+n,cmp);
cout<<num[0];
return 0;
}
后面变聪明了,用结构体封装flag,在输入的时候动手
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
struct hell
{
string num;
int flag;
}member[21];
bool cmp(hell a,hell b)//数组没必要标记
{
if(a.num.length()!=b.num.length()) return a.num.length()>b.num.length();
for(int i=0;i<a.num.length();i++)
{
if(a.num==b.num)continue;
else
{
return a.num>b.num;
break;
}
}
}
int main()
{
int n;scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>member[i].num;
member[i].flag=i+1;
}
sort(member,member+n,cmp);
printf("%d\n",member[0].flag);
cout<<member[0].num;
return 0;
}