zoukankan      html  css  js  c++  java
  • A1039 Course List for Student [unordered_map]

    在这里插入图片描述
    不用hash映射 就要用unordered_map 而且cin还要改成scanf cout改了更好

    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<unordered_map>
    #include<set>
    #include<map>
    using namespace std;
    int main()
    {
    	unordered_map<string, vector<int>>student;
    	int n, m;
    	scanf("%d %d", &n, &m);
    	for (int i = 0; i < m; i++)
    	{
    		int a, b;
    		scanf("%d %d", &a, &b);
    		for (int j = 0; j < b; j++)
    		{
    			string s;
    			s.resize(4);
    			scanf("%s", &s[0]);
    			student[s].push_back(a);
    		}
    	}
    	for (int i = 0; i < n; i++)
    	{
    		string s;
    		s.resize(4);
    		scanf("%s", &s[0]);
    		auto it=student.find(s);
    		sort(student[s].begin(), student[s].end());
    		if (it == student.end())
    		{
    			cout << s << " " << "0";
    		}
    		else
    		{
    			cout << it->first << " " << student[s].size();
    			for (auto it = student[s].begin(); it != student[s].end(); it++)
    					cout << " " << *it;
    		}
    		cout << endl;
    	}
    
    }
    
  • 相关阅读:
    泛型
    事件和委托
    参数和属性
    常量、字段、和方法
    LINQ
    LINQ- 子查询、组合策略、投影策略
    MySQL全局锁和表锁
    CLR基础
    LINQ
    LINQ
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812038.html
Copyright © 2011-2022 走看看