zoukankan      html  css  js  c++  java
  • ZOJ Problem Set 2947 Abbreviation

    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 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

    3
    4
    Super Harddisc Drive Cooler
    4
    Spade Heart Diamond Club
    3
    Shen Guang Hao
    3
    Shuai Ge Hao
    3
    Cai Piao Ge
    4
    C P C S
    

    Sample Output

    SAME
    SAME
    DIFFERENT
    

    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;
    }

  • 相关阅读:
    【设计模式(17)】行为型模式之中介者模式
    服务器迁移--MySQL数据库迁移
    巧妙解决element-ui下拉框选项过多的问题
    关于后台返回的文件流下载方法
    关于input框只让输入数字的写法
    关于element ui 全局配置某些组件的属性方法
    关于echarts的南丁格尔玫瑰图 极值导致展示效果不好的解决方案
    mock数据的使用方法
    配置 git账号和邮箱
    vite 发布了正式版版了 用起来
  • 原文地址:https://www.cnblogs.com/malloc/p/2096339.html
Copyright © 2011-2022 走看看