VectorPartitionLabels (string STR) {
Unordered_map & lt; Char, pairThe hash.
for(int i=0; iIf (hash. Find (STR) [I]==hash. The end ()) {
Hash. Insert ({STR [I] and {I, I}});
} else {
Hash [STR [I]]. Second=I;
}
}
VectorAns.
for(int i=0; iInt clidx=hash [I]. Second. Second;
The last line error as follows, consult everybody bosses how to solve? I just want to remove the second value pair to assign a value to an int variable clidx,
Line 14: Char 39: error: member reference base type "int" is not a structure or union
Int clidx=hash [I]. Second. Second;
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ^ ~ ~ ~ ~ ~ ~
CodePudding user response:
Unordered_map is not so traversalHash [] to return to the second element is the hash, namely pair, access to the second pair, get int, can't access the second int.
CodePudding user response:
You need to use this way to traverse theunordered_map & lt; Char, pair: : iterator iter.
For (iter=hash. The begin (); Iter!=hash. The end (); Iter++) {
Int x=(* iter). Second. Second;
}
CodePudding user response:
If there is an inner loop when j j how to write?
For (iter=hash. The begin (); Iter!=hash. The end (); Iter++) {
Iter int clidx=(*). Second. Second;
For (auto j=iter + 1; J!=hash. The end (); J++) {
Int nfidx=hash * [j]. Second. First;
J that do such write right error is as follows:
Line 18: Char 30: error: invalid operands to binary expression (' unordered_map & lt; Char, pair: : iterator '(aka' _Node_iterator & lt; STD: : pair , __constant_iterators: : value, __hash_cached: : value> ') and 'int')
For (auto j=iter + 1; J!=hash. The end (); J++) {
~ ~ ~ ~ ^ ~
CodePudding user response: