杭电1004题

来源:互联网 发布:淘宝手机优惠券 编辑:程序博客网 时间:2024/05/16 04:59

#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;} 
这个题其实没什么,就是用了链表来取代固定数组节省内存,并且每次比较完之后,会删除比较过的字符串,这样当数据比较大的时候,可能会节省时间,但是当数据比较小的时候,可能并不会节省时间,因为链表删除也会费时间的。

0 0
原创粉丝点击