uva 10887 Concatenation of Languages(STL set)
来源:互联网 发布:淘宝卖虚拟赚钱吗 编辑:程序博客网 时间:2024/06/01 07:54
Concatenation of Languages
Input File: Standard Input
Output: Standard Output
A language is a set of strings. And the concatenation of two languages is the set of all strings that are formed by concatenating the strings of the second language at the end of the strings of the first language.
For example, if we have two language A and B such that:
A = {cat, dog, mouse}
B = {rat, bat}
The concatenation of A and B would be:
C = {catrat, catbat, dograt, dogbat, mouserat, mousebat}
Given two languages your task is only to count the number of strings in the concatenation of the two languages.
Input
There can be multiple test cases. The first line of the input file contains the number of test cases, T (1≤T≤25). Then T test cases follow. The first line of each test case contains two integers, M and N (M,N<1500), the number of strings in each of the languages. Then the next M lines contain the strings of the first language. The N following lines give you the strings of the second language. You can assume that the strings are formed by lower case letters (‘a’ to ‘z’) only, that they are less than 10characters long and that each string is presented in one line without any leading or trailing spaces. The strings in the input languages may not be sorted and there will be no duplicate string.
Output
For each of the test cases you need to print one line of output. The output for each test case starts with the serial number of the test case, followed by the number of strings in the concatenation of the second language after the first language.
Sample Input Output for Sample Input
2
3 2
cat
dog
mouse
rat
bat
1 1
abc
cab
Case 1: 6
Case 2: 1
解题思路:STL中的set,有去重的功能,注意输入的是句子,可能有空格,所以要用gets读取。
#include <stdio.h>#include <string.h>#include <string>#include <set>#include <iostream>using namespace std;const int N = 1505;const int M = 105;char p[N][M], q[N][M], str[N];int main(){ set<string> vec; int cas = 1, n, m, sum, t; scanf("%d", &sum); while (sum--) {memset(p, 0, sizeof(p));memset(q, 0, sizeof(q));scanf("%d%d%*c", &n, &m);vec.clear();for (int i = 0; i < n; i++) gets(p[i]);for (int i = 0; i < m; i++) gets(q[i]);for (int i = 0; i < n; i++) { t = strlen(p[i]); for (int j = 0; j < m; j++) {strcpy(str, p[i]);strcpy(str + t, q[j]);vec.insert(str); }}cout << "Case " << cas++ << ": " << vec.size() << endl; } return 0;}
- uva 10887 Concatenation of Languages(STL set)
- 10887 - Concatenation of Languages(stl set)
- Uva 10887 Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- uva 10887 - Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- UVA 10887 Concatenation of Languages
- uva 10887 - Concatenation of Languages
- uva 10887 - Concatenation of Languages
- UVA 10887 Concatenation of Languages
- UVa:10887 Concatenation of Languages
- uva 10887Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- UVa 10887 - Concatenation of Languages
- UVA 10887 Concatenation of Languages
- UVA 10887 - Concatenation of Languages
- UVA - 10887 Concatenation of Languages
- UVA - 10887 Concatenation of Languages
- 【HDOJ】1106 -> 排序
- 我90后刚毕业后 做前端美工设计的一些经验
- Windows8.1安装SQL SERVER2008:为SQL Server代理服务提供的凭据无效
- 如何查硬盘是否4K对齐最原始的办法
- Eclipse_SVN
- uva 10887 Concatenation of Languages(STL set)
- HDU-4642-Fliping game
- Wooden Sticks
- 如何轻松屏蔽优酷、土豆等网站的视频广告
- Linux 中使用 KVM
- packets
- C++内存管理学习笔记(1)
- linux运行级别
- 突然感觉很孤独