UVA - 10887 Concatenation of Languages
来源:互联网 发布:先锋软件职业技术学院 编辑:程序博客网 时间:2024/04/30 08:26
Problem A
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 10 characters 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
题意:
给出两种语言,然后在重新链接,求出其个数:
#include <iostream>#include <cstdio>#include <cstring>#include <set>#define N 1500using namespace std;set <string> Set;int main() {int n;int u, v;char a[N][N], b[N][N],c[N];scanf("%d",&n);for (int i = 1; i <= n; i++) {printf("Case %d:",i);scanf("%d%d",&u,&v);getchar();Set.clear();for (int i = 0; i < u; i++) {gets(a[i]);//puts(a[i]);}for (int i = 0; i < v; i++) {gets(b[i]);//puts(b[i]);}for (int i = 0; i < u; i++)for (int j = 0; j < v; j++) {strcpy(c,a[i]); // 没有这一步会超时Set.insert(strcat(c,b[j]));}printf(" %d\n",Set.size());}}
- 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
- UVa 10887 - Concatenation of Languages
- uva 10887Concatenation of Languages
- Python网络编程入门
- IOS常见错误分析解决(一直更新)
- 通过wifi调试android程序
- 【MATLAB】RGB,HSV,LAB
- 数据库批量插入数据优化 prest.execute()与prest.executeBatch()
- UVA - 10887 Concatenation of Languages
- C++析构函数为什么要为虚函数
- Core Bluetooth for iOS 6
- 哪些食物最养胃
- java 保留2位小数
- 正则表达式用法及实例
- Train Problem I(STL)基本运用stack
- LeetCode 125. Valid Palindrome
- 常州丰胸手术大概要多少钱