可以说我有1个矢量名称和另一个电话号码矢量。 首先,用户将输入姓名(不排序,意味着他们不是从a到z),然后,用户将输入相应的电话号码。
在填充两个向量之后,程序然后在名称向量(向量1)中执行排序机制。 问题现在是矢量2(因为没有采用机制将其映射到矢量1)。
例:
vector name | vector telephone f 232132 a 34242342 b 997345 the result will be vector name | vector telephone a 232132 b 34242342 f 997345正如你所看到的,矢量电话尚未调整。 我们该如何调整呢? 谢谢
lets say I have 1 vector of names and another vector for the telephone numbers. First, the user will enter names (not sorted, meaning they are not organized from a to z), then, the user will enter the corresponding telephone number.
After filling out both vectors, the program then executes sorting mechanism in the name vector(vector 1). The problem is now the vector 2, (since there is no adopting mechanism to map it to vector 1).
Example:
vector name | vector telephone f 232132 a 34242342 b 997345 the result will be vector name | vector telephone a 232132 b 34242342 f 997345as you can see, the vector telephone hasnt been adjusted. how can we adjust this?? thanks
最满意答案
创建一个包含名称字符串和电话号码字符串/ int的结构体。 线性查看并记录名称信息。 再次浏览并记录手机号码信息。 然后排序。
如果你不想创建一个类,你可以使用一个pair对象。
vector<pair<string,int> > nameAndNumber;编辑:修正了一个错误,谢谢smocking
Create a struct that holds a string for the name and a string/int for the phone number. Go through it linearly and record the name information. Go through it again and record the phone # information. Then sort.
If you do not wish to create a class, you can use a pair object.
vector<pair<string,int> > nameAndNumber;Edit: fixed a bug, thanks smocking
更多推荐
发布评论