思路及代码
//input 多组
//input n 1<=n<=100
//input numbers
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
while (cin >> n){
vector<int> list;
int ele;
cin >> ele;
list.push_back(ele);
//at the same time ,isinlist,add/continue
for (int i = 1; i <= n-1; i++){
cin >> ele;
int cnt = (int) count(list.begin(), list.end(), ele);
if (cnt == 0){
list.push_back(ele);
}
}
//cout list
cout << list.at(0);
for (int i = 1; i <= list.size()-1; i++){
cout << " " << list.at(i);
}
cout << endl;
}
return 0;
}
参考:1️⃣DHU OJ 一维数组 人见人爱A-B 题解 未发
2️⃣https://www.cnblogs.com/xylc/p/3653036.html
收获:1️⃣复习查找某个元素是否在数组中
用 count ()函数
2️⃣遍历 vector 数组的一种方式 下标法 方便控制取多少元素
for (int i = 0 ; i <= list.size()-1; i++){
cout << list.at(i);
}
菜菜,不是教程,做题和学习记录