当前位置:网站首页>Concatenation of Languages(UVA10887)
Concatenation of Languages(UVA10887)
2022-06-30 03:55:00 【Cod_ ing】
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
2
3 2
cat
dog
mouse
rat
bat
1 1
abc
cab
Sample Output
Case 1: 6
Case 2: 1
This topic is really unclear , Although the string is composed of “a to z” constitute 、 No spaces , But there is a need to Blank line As string , therefore :a+ Blank line and Blank line +a Is a duplicate string .
therefore , You can use set The container automatically excludes duplicate elements , use getline(cin,s) Read string ( Use getline when , Pay attention to whether the previous use of scanf 、cin, If you have any , need getchar() Read unread \n ).
#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE=1505;
string s1[MAXSIZE];
string s2[MAXSIZE];
int main()
{
int n,eg=0,i,M,N,j;
string temp;
set <string> S;
cin>>n;
while(n--)
{
eg++;
cin>>M>>N;
getchar(); // Read cin Bequeathed \n
for(i=0;i<M;i++)
getline(cin,s1[i]);
for(i=0;i<N;i++)
getline(cin,s2[i]);
for(i=0;i<M;i++)
for(j=0;j<N;j++)
{
if(s1[i][0]==' '&&s2[j][0]!=' ')
{
S.insert(s2[j]);
}
else if(s1[i][0]!=' '&&s2[j][0]==' ')
{
S.insert(s1[i]);
}
else
{
temp=s1[i]+s2[j];
S.insert(temp);
}
}
cout<<"Case "<<eg<<": "<<S.size()<<endl;
S.clear();
}
}
边栏推荐
- 深入浅出掌握grpc通信框架
- Green new power and "zero" burden of computing power -- JASMINER X4 series is popular
- Number of students from junior college to Senior College (4)
- 【笔记】2022.6.7 数据分析概论
- [Thesis reading | deep reading] role2vec:role based graph embeddings
- [0x0] open questions left by the principal
- Integrating viewbinding and viewholder with reflection
- Semantic segmentation resources
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- SDS understanding in redis
猜你喜欢

巧用 Bitmap 实现亿级海量数据统计

11: I came out at 11:04 after the interview. What I asked was really too

Solve the problem of Navicat connecting to the database

Buffer pool of MySQL notes

Selenium environment installation, 8 elements positioning --01

Green new power and "zero" burden of computing power -- JASMINER X4 series is popular

EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?

Laravel9 local installation

第十二天 进阶编程技术

RPC correction
随机推荐
SDS understanding in redis
Hebb and delta learning rules
[image fusion] multi focus and multi spectral image fusion based on cross bilateral filter and weighted average with matlab code
[note] May 23, 2022 MySQL
124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)
How to use FME to create your own functional software
【常见问题】浏览器环境、node环境的模块化问题
Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column
I have published a book, "changing life against the sky - the way for programmers to become gods", which is open source. I have been working for ten years. There are 100 life suggestions from technica
Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
【笔记】2022.5.23 MySQL
Product thinking - is the future of UAV express worth looking forward to?
Radiant energy, irradiance and radiance
[operation] write CSV to database on May 28, 2022
【作业】2022.5.28 将CSV写入数据库
Chapter 2 control structure and function (programming problem)
Version correspondence table of tensorflow, CUDA and bazel
[cloud native] AI cloud development platform - Introduction to AI model foundry (developers can experience AI training model for free)
Practical debugging skills
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()