当前位置:网站首页>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();
}
}
边栏推荐
- SQL server2005中SUM函数中条件筛选(IF)语法报错
- [0x0] open questions left by the principal
- From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
- Chapter 2 control structure and function (programming problem)
- 【常见问题】浏览器环境、node环境的模块化问题
- Laravel9 local installation
- 两个月拿到N个offer,什么难搞的面试官在我这里都不算事
- Hebb and delta learning rules
- 124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)
- 尝试链接数据库时出现链接超时报错,如何解决?
猜你喜欢

The jupyter notebook kernel hangs up frequently and needs to be restarted

第十天 数据的保存与加载

Product thinking - is the future of UAV express worth looking forward to?

laravel9本地安装

Day 9 script and resource management

Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0

SDS understanding in redis

The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database

Simple theoretical derivation of SVM (notes)

Geometric objects in shapely
随机推荐
深入浅出掌握grpc通信框架
When easycvr deploys a server cluster, what is the reason why one is online and the other is offline?
(03). Net Maui actual combat basic control
Grasp grpc communication framework in simple terms
【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码
Semantic segmentation resources
利用反射整合ViewBinding和ViewHolder
[cloud native] AI cloud development platform - Introduction to AI model foundry (developers can experience AI training model for free)
【作业】2022.5.25 MySQL 查操作2
dotnet-exec 0.5.0 released
Hebb and delta learning rules
UML图与List集合
[operation] MySQL query on May 24, 2022
Huawei cloud native - data development and datafactory
王爽-汇编语言 万字学习总结
[Thesis reading | deep reading] role2vec:role based graph embeddings
Pytorch Profiler+ Tensorboard + VS Code
From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
MySQL performance optimization (6): read write separation
Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0