• hdu 2034


    题意:集合A,B,计算集合差A-B(求只在集合A内的数)

    解法:

    选用STL内的集合set

    1.建立set

       1:  #include<set>
       2:   
       3:  set<int> se;

    2.关于集合的遍历,固定的格式:

    用容器的iterator访问所有数据。

       1:  for(set<int>::iterator it=a.begin();it!=a.end();it++){
       2:      //TO DO
       3:  }

    3.相应的用*it访问set内的数据

    4.set内的数据会自动排序,从小到大的顺序。

    5.关于find()操作:

    如果找不到,会返回set.end()

    附上我的代码:

       1:  #include<iostream>
       2:  #include<cstdio>
       3:  #include<cstdlib>
       4:  #include<string>
       5:  #include<string.h>
       6:  #include<set>
       7:  using namespace std;
       8:  int main(){
       9:      int n,m,tmp;
      10:      while(scanf("%d %d",&n,&m)!=EOF&&(n||m)){
      11:          set<int> a,b;
      12:          while(n--){
      13:              scanf("%d",&tmp);
      14:              a.insert(tmp);
      15:          }
      16:          while(m--){
      17:              scanf("%d",&tmp);
      18:              b.insert(tmp);
      19:          }
      20:          int cnt=0;
      21:          for(set<int>::iterator it=a.begin();it!=a.end();it++){
      22:              if(b.find(*it)==b.end()){
      23:                  printf("%d ",*it);
      24:                  cnt++;
      25:              }
      26:          }
      27:          if(cnt==0)printf("NULL");
      28:          printf("
    ");
      29:      }
      30:  }
      31:      
  • 相关阅读:
    如何手动封装 $ on off emit?
    Vue 实例身上的一些方法(二)
    Vue 实例身上的一些方法(一)
    Vue属性过滤
    Vue属性监听
    Vue实现简单的商品增减功能
    Vue 计算属性
    使用Vue实现一个简单地自定义拖拽功能
    数组的深拷贝与浅拷贝
    如何让html引用公共布局(多个html文件公用一个header.html和footer.html)
  • 原文地址:https://www.cnblogs.com/ZJUT-jiangnan/p/3656199.html
Copyright © 2020-2023  润新知