vector去重
  • 板块学术版
  • 楼主hoyoo
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/11/17 17:28
  • 上次更新2023/11/5 07:50:44
查看原帖
vector去重
370419
hoyoo楼主2020/11/17 17:28
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;vector<int>x;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>b;
        x.push_back(b);
    }
    for(int i=0;i<a;i++)
        for(int j=2;j<a;j++)
           if(*x.begin()+i==*x.begin()+j)
            {
              x.erase(x.begin()+j,x.begin()+j);
            }
    for(int i=0;i<x.size();i++)
         cout<<*x.begin()+i<<' ';
}

纯蒟蒻,这样写为什么不行呢

2020/11/17 17:28
加载中...