Struct is used for map. operators must be reloaded when set. <

Source: Internet
Author: User
#include<iostream>#include<set>using namespace std;struct P{int entry;    int time;bool operator<(const P  &b)const{return (this->entry<b.entry);}};int main(){while(!cin.eof()){int n;cin>>n;set<P> s;P tmp;for(int i = 0;i<n;i++){tmp.time = 1;cin>>tmp.entry;if(s.find(tmp)==s.end())s.insert(tmp);else{set<P>::iterator it;it = s.find(tmp);tmp=*it;tmp.time++;s.erase(it);s.insert(tmp);}}set<P>::iterator itr;for(itr = s.begin();itr!=s.end()&&!cin.eof();itr++)if(itr->time % 2)cout<<itr->entry<<endl;}}

Example: # include <map> # include <iostream> # include <string> using namespace STD; // student information typedef struct tagstudentinfo {int NID; string strname; bool operator <(const tagstudentinfo & A) const {If (NID <. NID) return true; // compare NID if (nid =. NID) return strname. compare (. strname) <0; // compare strname return false;} studentinfo, * pstudentinfo;

 

 

Struct is used for map. operators must be reloaded when set. <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.