hdu 1412 (STL list)

简单例题

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1412

list 相关博客:http://www.cnblogs.com/fangyukuan/archive/2010/09/21/1832364.html

 1 #include <stdio.h>
 2  #include <list>
 3  #include <string.h>
 4  using namespace std;
 5  
 6  int main()
 7  {
 8      int n,m,a[10005],b[10005],i,j;
 9      while(~scanf("%d%d",&n,&m))
10      {
11          for(i = 0; i<n; i++)
12              scanf("%d",&a[i]);
13          for(i = 0; i<m; i++)
14              scanf("%d",&b[i]);
15          list<int> la;
16          list<int> lb;
17          for(i = 0; i<n; i++)
18              la.push_back(a[i]);
19          for(i = 0; i<m; i++)
20              lb.push_back(b[i]);
21          la.merge(lb);
22          la.sort();
23          la.unique();//先排序才能去重,否则不行
24          int cnt = 0;
25          while(!la.empty())
26          {
27              if(!cnt)
28                  printf("%d",la.front());
29              else
30                  printf(" %d",la.front());
31              cnt++;
32              la.pop_front();
33          }
34          printf("
");
35      }
36  
37      return 0;
38  }
原文地址:https://www.cnblogs.com/bfshm/p/3232028.html