题解 | 特殊城市

特殊城市

https://www.nowcoder.com/practice/46f68af83db74b709a788dedb656c5f9

#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
using namespace std;

int main() {
    int count;
    cin >> count;
    unordered_map<string,vector<string>> stateMap;
    int res =0;
    while(count--){
        string city,state;
        cin >> city >> state;
        if(city.substr(0,2) == state) continue;
        if(stateMap.find(city.substr(0,2)) != stateMap.end()){
            for(auto i : stateMap[city.substr(0,2)]){
                if(i.substr(0,2) == state){
                    res++;
                }
            }
        }
        stateMap[state].push_back(city);
        
    }
    cout << res <<endl;

}
// 64 位输出请用 printf("%lld")

全部评论
vector换成unordered_set就会报错 至今不知道原因 希望有人能答疑
点赞 回复 分享
发布于 08-04 12:06 辽宁

相关推荐

看起来名字可以很长:笑死 我暑期实习阿里云的意向也被 qq 邮箱放在垃圾箱了
点赞 评论 收藏
分享
苗条的伊泽瑞尔最喜欢...:同28届被压力了,电科✌就不能去卷算法吗?把Java留给我们双非卷
投递快手等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务