Update
This commit is contained in:
@@ -237,13 +237,10 @@ public:
|
||||
```cpp
|
||||
for (pair<const string, int>& target : targets[result[result.size() - 1]])
|
||||
```
|
||||
pair里要有const,因为map中的key是不可修改的,所以是`pair<const string, int>`。
|
||||
|
||||
如果不加const,也可以复制一份pair,例如这么写:
|
||||
一定要加上引用即 `& target`,因为后面有对 target.second 做减减操作,如果没有引用,单纯复制,这个结果就没记录下来,那最后的结果就不对了。
|
||||
|
||||
```cpp
|
||||
for (pair<string, int>target : targets[result[result.size() - 1]])
|
||||
```
|
||||
加上引用之后,就必须在 string 前面加上 const,因为map中的key 是不可修改了,这就是语法规定了。
|
||||
|
||||
|
||||
## 总结
|
||||
|
||||
Reference in New Issue
Block a user