首页 > 其他 > 详细

uva-10887-枚举

时间:2018-11-04 01:14:57      阅读:150      评论:0      收藏:0      [点我收藏+]

题意:集合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;
}

  

uva-10887-枚举

原文:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9902688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!