--- title: "商品总类" created: 2025-11-28 tags: - 算法 --- # 商品总类 ## 题目 [商品种类](https://www.acwing.com/problem/content/description/4722/) ![[image-88d02237.png]] ## 思路分析 只要看某个串是否出现过 用unordered\_set 注意不能直接拼接 ab c 和 a bc是不一样的 拼接时加个空格 ## 代码实现 **哈希表 17 ms** ```cpp #include using namespace std; unordered_set hashtb; int main() { int n; cin>>n; while(n--){ string a,b; cin>>a>>b; hashtb.insert(a+' '+b); } cout< using namespace std; #define endl '\n' typedef pair PSS; set hx; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n;cin>>n; while(n--){ string a,b;cin>>a>>b; hx.insert({a,b}); } cout<