help
查看原帖
help
1247040
V_HAPPY666楼主2024/8/24 11:13
#include <bits/stdc++.h>
using namespace std;

struct Word
{
	string word;
	int l,cnt;
}a[2024];
int pos;
bool cmp(Word x,Word y)
{
	return (x.l<y.l)||(x.l==y.l&&x.cnt<y.cnt);
}
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	while(cin>>s)
	{
		if((int)s.find(',')!=-1)
		{
			s.erase(s.begin()+s.find(','));
		}
		if((int)s.find('.')!=-1)
		{
			s.erase(s.begin()+s.find('.'));
		}
		a[pos].word=s;
		a[pos].l=s.length();
		a[pos].cnt=pos;
		pos++;
	}
	sort(a,a+pos,cmp);
	cout<<a[--pos].word<<endl<<a[0].word;
	return 0;
}
2024/8/24 11:13
加载中...