如何能够检查输入数据与之前的输入数据相同
How to be able to check the input data is the same from previous input data?
我有一个分配,提供了一个数据集。我创建了一个结构数组,想要输入值,但不知道如何输入值,而不让它在同一数组中重复。
例如,数据集中有18名女性,她们参加了各自的活动。
e。g
Tiffany, E1
Tiffany, E2
Tiffany, E3
Tiffany, E4
Tiffany, E5
Tiffany, E6
Tiffany, E8
Tiffany, E9
Dione, E1
Dione, E2
Dione, E3
Dione, E5
Dione, E6
Dione, E7
Dione, E8
Kelly, E2
Kelly, E3
Kelly, E4
Kelly, E5
Kelly, E6
Kelly, E7
Kelly, E8
Kelly, E9
我可以使用什么样的代码,以便当我输入数据集时,第一个结构数组分配给Tiffany和她各自的事件E1, E2, E3等,第二个结构数组将有Dione和她参加的事件。在数据集中,不同的女性参加了不同数量的活动。我想知道它是否能够检查第一个输入是名字是否相同,以便创建一个新的数组,如果它是另一个女人。
如果你不能使用STL,它就像迭代数组一样简单,然后找到每个人改变它的事件。下面可以看到一个伪代码:
string prevName="", currName;
//read currName and event from the file
if (prevName != currName){
//create a new entry in the array
prevName = currName;
}
//add event in the current array position
但是你也可以这样使用STL:
//These header are needed
#include <map>
#include <string>
#include <vector>
using namespace std;
//this is an example of defining persons and events
string p = "Tiffany", e = "E1";
//this is our data structure to keep records of people
map<string, vector<string> > PersonEvent;
//updating is as simple as calling this function
PersonEvent[p].push_back(e);
//going through every record of a person
for(int i=0; i<PersonEvent[p].size(); i++)
//do something with PersonEvent[p][i]
相关文章:
- 我的程序没有从文件中读取并输入数据
- 输入数据成员未按要求工作
- 使用 pybind11 调用 Python 函数时避免复制输入数据
- 使用 python 或 c ++ 中的 sql 根据输入数据输出输出示例
- c++用输入数据创建数组
- Caffe 或 Caffe2 可以直接从 GPU 获得输入数据吗?
- C++ QTextDocument::contentChange() 信号提供无效的输入数据
- boost::asio 以async_read复制输入数据
- 输入数据类型检查循环未按预期工作 (C++)
- SVM 训练时间是否取决于输入数据的内容?
- 将用户输入数据相加
- 在线评委如何传递输入数据?
- 如何传递私有地图和输入数据
- C++ 将用户输入数据用于多个函数
- 通过按空格键结束键盘输入数据,而不是输入键 c/c++
- 如何为作为雇员类的指针传入的构造函数输入数据
- C++:检查输入数据
- 关于输入数据
- 防止在管道中输入数据时退出
- C/C++中固定长度实输入数据的高效二维FFT