首页 > 代码库 > stl set使用

stl set使用

  1. #include <set>
  2. #include <iostream>
  3. #include <stdio.h>
  4. using namespace std;
  5. int main()
  6. {
  7. int n,m;
  8. while(scanf("%d%d",&n,&m)!=EOF && n!=-1 && m!=-1)
  9. {
  10. set <int > R_num;
  11. set <int > B_num;
  12. for(int i=1; i<=m; i++)
  13. {
  14. int x,y;
  15. scanf("%d%d",&x,&y);
  16. if(i%2!=0)
  17. {
  18. R_num.insert(x);
  19. R_num.insert(y);
  20. if(B_num.find(x)!=B_num.end() )
  21. B_num.erase(x);
  22. if(B_num.find(y)!=B_num.end() )
  23. B_num.erase(y);
  24. }
  25. else
  26. {
  27. B_num.insert(x);
  28. B_num.insert(y);
  29. if(R_num.find(x)!=R_num.end() )
  30. R_num.erase(x);
  31. if(R_num.find(y)!=R_num.end() )
  32. R_num.erase(y);
  33. }
  34. }
  35. if(B_num.size()==n)
  36. printf("YES\n");
  37. else
  38. printf("NO\n");
  39. set<int >::iterator iter;
  40. for(iter=R_num.begin(); iter!=R_num.end(); iter++)
  41. cout << *iter << endl;
  42. }
  43. return 0;
  44. }



来自为知笔记(Wiz)


附件列表

     

    stl set使用