当前位置:网站首页>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();
}
}
边栏推荐
- NER中BiLSTM-CRF解读score_sentence
- (04). Net Maui actual MVVM
- [punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
- 第十天 数据的保存与加载
- Analysis of similarities and differences of various merged features (Union, merge, append, resolve) in ArcGIS
- [punch in - Blue Bridge Cup] day 5 --- lower() small
- Node red series (28): communication with Siemens PLC based on OPC UA node
- yarn的安装和使用
- dotnet-exec 0.5.0 released
- Linear interpolation of spectral response function
猜你喜欢
11: I came out at 11:04 after the interview. What I asked was really too
【笔记】AB测试和方差分析
Smart use of bitmap to achieve 100 million level massive data statistics
【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码
Selenium environment installation, 8 elements positioning --01
[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII
Redis high concurrency distributed locks (learning summary)
dotnet-exec 0.5.0 released
绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
两个月拿到N个offer,什么难搞的面试官在我这里都不算事
随机推荐
Huawei cloud native - data development and datafactory
dbt产品初体验
Node red series (28): communication with Siemens PLC based on OPC UA node
A minimalist way to integrate databinding into activity/fragment
(03). Net Maui actual combat basic control
(04).NET MAUI实战 MVVM
Solve the problem of Navicat connecting to the database
[cloud native] AI cloud development platform - Introduction to AI model foundry (developers can experience AI training model for free)
Installation and use of yarn
From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
你清楚AI、数据库与计算机体系
【常见问题】页面跨域和接口跨域
ReSharper 7. Can X be used with vs2013 preview? [off] - can resharper 7 x be used with VS2013 preview? [closed]
NER中BiLSTM-CRF解读score_sentence
(Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
About manipulator on Intelligent Vision Group
[FAQ] page cross domain and interface Cross Domain
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
Pytorch Profiler+ Tensorboard + VS Code