题目不严谨
查看原帖
题目不严谨
439327
南瓜桐楼主2022/4/11 14:49

测试点中有两个人票数相同的情况,题目中并没有说票数相同是输出哪一个,
这是AC的代码:

#include <iostream>
#include <cstdio>
using namespace std;
namespace wzl{
int n,num=1;
string a[30]={}; 
void main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i = 1; i <= n; ++i){
		cin>>a[i];
	}
	string maxx = a[1];
	for(int i = 2; i <= n; ++i){
		if(maxx.size() < a[i].size()){
			maxx = a[i];
			num = i;
		}else if(maxx.size() == a[i].size()){
			maxx = max(maxx,a[i]);
			if(maxx <= a[i]){
				num = i;
				maxx = a[i];
			}
		}
	}
	cout<<num<<endl<<maxx;
	return;
}
}


int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	wzl::main();
	return 0;
}

当我把第行的maxx <= a[i]改成maxx < a[i]就过不了了,显然当遇到票数相同是要输出后面的,但题目中并没有说

2022/4/11 14:49
加载中...