Zoj problem set-2947 abbreviation

Source: Internet
Author: User
Zoj problem set-2947 Abbreviation

Time limit:1 second Memory limit:32768 KB

When a little white meets another little white:

Little white A: (Surprised )!
Little white B :?
Little white A: You little white know "SHDC "? So unbelievable!
Little white B: you are little white! Little white is you! What is "SHDC" you are talking about?
Little white A: Wait... I mean "super hard-disc drive cooler ".
Little white B: I mean "spade heart Diamond Club"... duck talks with chicken -_-//
Little white A: Duck... chicken... faint!

------ Quote from qmd of spade6 in cc98 forum.

Sometimes, we write the abbreviation of a name. for example IBM is the abbreviation for International Business Machines. A name usually consists of one or more words. A word begins with a capital letter ('A'-'Z') and followed by zero or more lower-case letters ('A'-'Z '). the abbreviation for a name is the word that consists of all the first letters of the words.

Now, you are given two names and asked to decide whether their abbreviations are the same.

Input

Standard input will contain multiple test cases. The first line of the input is a single integerTWhich is the number of test cases. And it will be followedTConsecutive test cases.

There are four lines for each case.
The first line contains an integerN(1 <=N<= 5), indicating the number of words in the first name.
The second line shows the first name.
The third line contains an integerM(1 <=M<= 5), indicating the number of words in the second name.
The fourth line shows the second name.
Each name consists of several words separated by space. Length for every word is less than 10. The first letter for each word is always capital and the rest ones are lower-case.

Output

Results shocould be directed to standard output. The output of each test case shocould be a single line. If two names 'abbreviations are the same, output "same", otherwise output "different ".

Sample Input

34 super Harddisc drive cooler4spade heart diamond club3shen Guang hao3shuai Ge hao3cai Piao ge4c P C S

Sample output

 
Samesamedifferent
Author: Hang, Hang
Source: Zhejiang University local contest 2008 Source code:

 # Include  <  Iostream  >  
# Include < String >
Using Namespace STD;

Const String Same = " Same " ;
Const String Different = " Different " ;

String Getabbreviations ( Int Stirngcount)
{
String Result = "" ;
String Name;
While (Stirngcount -- )
{
CIN > Name;
Result + = Name [ 0 ];
}
Return Result;
}
Int Main ()
{
Int Cases; CIN > Cases;
While (Cases -- )
{
Int Numinfirstname; CIN > Numinfirstname;
String Fabbreviations = Getabbreviations (numinfirstname );

Int Numinlastname; CIN > Numinlastname;
String Labbreviations = Getabbreviations (numinlastname );

If (Fabbreviations. Compare (labbreviations) = 0 )
{
Cout < Same;
}
Else
{
Cout < Different;
}
Cout < Endl;
}
Return 0 ;
}

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.