zoukankan      html  css  js  c++  java
  • uva-10887-枚举

    题意:集合S1和S2,把S2中的元素拼接到S1的后面去,生成新的元素,问有多少个不重复的元素

    直接map.注意,不能用cin读取字符串,题目没有保证字符串中间没有空格

    #include "pch.h"
    #include <string>
    #include<iostream>
    #include<map>
    #include<memory.h>
    #include<vector>
    
    
    namespace cc
    {
    	using std::cout;
    	using std::endl;
    	using std::cin;
    	using std::map;
    	using std::vector;
    	using std::string;
    
    	int n;
    	int t;
    	int r, c;
    	int total;
    	constexpr int N = 1501;
    	string set1[N];
    	string set2[N];
    	map<string, int>allMaps;
    	void cal()
    	{
    		for (int i = 0;i < r;i++)
    		{
    			for (int j = 0;j < c;j++)
    			{
    				string str = set1[i] + set2[j];
    				if (allMaps[str] == 0)
    				{
    					++total;
    					allMaps[str] = 1;
    				}
    			}
    		}
    	}
    	void read()
    	{
    		total = 0;
    		allMaps.clear();
    		cin >> r >> c;
    		getchar();
    		for (int i = 0;i < r;i++)
    			getline(cin,set1[i]);
    		for (int i = 0;i < c;i++)
    			getline(cin, set2[i]);
    
    	}
    
    	void solve()
    	{
    		t = 1;
    		cin >> n;
    		while (n--)
    		{
    			read();
    			cal();
    			cout << "Case " << t << ": " << total << endl;
    			t++;
    		}
    	}
    
    };
    
    
    int main()
    {
    
    #ifndef ONLINE_JUDGE
    	freopen("d://1.text", "r", stdin);
    #endif // !ONLINE_JUDGE
    	cc::solve();
    
    	return 0;
    }
    

      

  • 相关阅读:
    MySQL多表查询
    多表关联
    MySQL数据类型 约束
    初识数据库
    socker server和 event
    os 模块 和 os模块下的path模块
    sys 模块
    time 模块
    目录规范

  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9902688.html
Copyright © 2011-2022 走看看