64,637
社区成员
发帖
与我相关
我的任务
分享
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned char uchar;
typedef struct _MyDATA
{
uchar _data[10];
_MyDATA(uchar data[10])
{
memcpy(_data, data, 10);
}
bool operator==(const uchar data[])
{
return memcmp(_data, data, 10) == 0;
}
}MYDATA;
typedef vector<MYDATA> MyCont;
int main(int argc, char* argv)
{
MyCont cont;
uchar data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
if(find(cont.begin(), cont.end(), data) != cont.end())
{
cont.push_back(data);
}
}
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> v;
string str;
while(cin >> str) // 输入字符串
{
int flag = 1;
vector<string>::iterator beg = v.begin();
for(;beg!=v.end(); ++beg)
{
if((*beg).compare(str) == 0) // 比较字符串,相等返回0
{
flag = 0;
break;
}
}
if(flag == 1)
{
v.push_back(str);
}
}
// 输出
vector<string>::iterator beg = v.begin();
for(;beg!=v.end(); ++beg)
cout << *beg << " ";
cout << endl;
return 0;
}