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;
    }
    

      

  • 相关阅读:
    tar命令,vi编辑器
    Linux命令、权限
    Color Transfer between Images code实现
    利用Eclipse使用Java OpenCV(Using OpenCV Java with Eclipse)
    Matrix Factorization SVD 矩阵分解
    ZOJ Problem Set
    Machine Learning
    ZOJ Problem Set
    ZOJ Problem Set
    ZOJ Problem Set
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9902688.html
Copyright © 2011-2022 走看看