ACM程序设计 书中题目Z

来源:互联网 发布:sqlserver 大数据导入 编辑:程序博客网 时间:2024/05/20 06:54

Description

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 integer T which is the number of test cases. And it will be followed by T consecutive test cases.

There are four lines for each case.
The first line contains an integer N (1 <= N <= 5), indicating the number of words in the first name.
The second line shows the first name.
The third line contains an integer M (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 should be directed to standard output. The output of each test case should be a single line. If two names' abbreviations are the same, output "SAME", otherwise output "DIFFERENT".

Sample Input

34Super Harddisc Drive Cooler4Spade Heart Diamond Club3Shen Guang Hao3Shuai Ge Hao3Cai Piao Ge4C P C S

Sample Output

SAMESAME

DIFFERENT

这道题的意思是判断缩写是否相同,即每个单词的首字母。

没什么难度,代码如下:

#include <bits/stdc++.h>using namespace std;int main(){        int a[100],i,n,j,x,y;        char l[5][100],m[5][100];        cin>>n;        for(i=0;i<n;i++)        {                cin>>x;                for(j=0;j<x;j++)                        cin>>l[j];                cin>>y;                for(j=0;j<y;j++)                        cin>>m[j];                if(x!=y)                        cout<<"DIFFERENT"<<endl;                else                {                        for(j=0;j<x;j++)                                if(l[j][0]!=m[j][0])                                {                                        cout<<"DIFFERENT"<<endl;                                        break;                                }                        if(x==j)                                cout<<"SAME"<<endl;                }        }}

0 0
原创粉丝点击