输不出下标!
查看原帖
输不出下标!
577422
skyark1214楼主2022/5/8 15:16
#include<bits/stdc++.h>
using namespace std;
struct Person {
	int num;
	char vote[101];
	int slen;
};
char maxxup[101];
Person peo[21];
int main() {
	int b;
	int maxxlen=-1;
	int max=0;
	cin>>b;
	for(int i=1; i<=b; ++i) {
		gets(peo[i].vote);
		peo[i].slen=strlen(peo[i].vote);
		if(peo[i].slen>maxxlen) {
			maxxlen=peo[i].slen;
			max=i;
			strcpy(maxxup,peo[i].vote);
		}
		if(peo[i].slen==maxxlen) {
			for(int j=0; j<maxxlen; ++j) {
				if(peo[i].vote[j]>maxxup[j]) {
					maxxlen=peo[i].slen;
					max=i;
					strcpy(maxxup,peo[i].vote);
					break;
				}
			}
		}
	}
	cout<<max<<endl;
	puts(maxxup); 
}
2022/5/8 15:16
加载中...