UVA 10887 concatenation of Languages

Source: Internet
Author: User

Original question:
A language is a set of strings. And the concatenation of languages is the set of all strings that's formed by concatenating the strings of the Secon D language at the end of the strings of the first language.
For example, if we have both 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 The languages your task is only to count the number of strings in the concatenation of the.
Input
There can 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 all test case contains-integers, M and N (M,n <), the number of strings in each of the Lang Uages. 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 is formed by lower case letters (' a ' to ' Z ') only, that they is less than characters Long and that are presented in one line without any leading or trailing spaces.
The strings in the input languages is sorted and there would 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 the The test case, followed by the number of the strings in the con Catenation 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


English:
Give you two sets of strings, A, B, let's connect the two groups together. The string in the string in the first B is followed by the number of times you have concatenated strings.


#include<bits/stdc++.h>
using namespace std;
vector<string> A,B,C;
int t;
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    int k=1;
    while(t--)
    {
        int m,n;
        A.clear();
        B.clear();
        C.clear();
        cin>>m>>n;
        cin.ignore();
        for(int i=0;i<m;i++)
        {
            string s;
            getline(cin,s);
            A.push_back(s);
        }
        for(int i=0;i<n;i++)
        {
            string s;
            getline(cin,s);
            B.push_back(s);
        }
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
                C.push_back(A[i]+B[j]);
        sort(C.begin(),C.end());
        int ans=unique(C.begin(),C.end())-C.begin();
        cout<<"Case "<<k++<<": "<<ans<<endl;
    }
    return 0;
}


Answer:



I'm ashamed of doing this water problem ...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.