概述
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main() {
list<string> slist;
list<string> answer;
string temp , result , sear;
int inNum = 0, i, max , sum;
list<string>::iterator pos;
list<string>::iterator del;
while (cin>>inNum) {
result = "";
max = 0;
if (inNum == 0) {
break;
}
for (i = 0 ; i < inNum ; i++) {
cin >> temp;
slist.push_back(temp);
}
while (slist.begin() != slist.end()) {
sum = 0;
pos = slist.begin();
sear = *pos;
for(pos = slist.begin(); pos != slist.end();) {
if (sear == *pos) {
++sum;
del = pos;
++pos;
slist.erase(del);
} else {
++pos;
}
}
if (sum > max) {
max = sum;
result = sear;
}
}
answer.push_back(result);
}
for (pos = answer.begin(); pos != answer.end(); ++pos ) {
cout << *pos << endl;
}
return 0;
}
这个题其实没什么,就是用了链表来取代固定数组节省内存,并且每次比较完之后,会删除比较过的字符串,这样当数据比较大的时候,可能会节省时间,但是当数据比较小的时候,可能并不会节省时间,因为链表删除也会费时间的。
最后
以上就是端庄豌豆为你收集整理的杭电1004题的全部内容,希望文章能够帮你解决杭电1004题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复