2.6 Abbreviation

2.6.1 时空限制

Time limit: 1 Seconds Memory limit: 32768K

2.6.2 题目内容

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


               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

2.6.3 题目来源

Zhejiang University Local Contest 2008(Author: HANG, Hang) 

2.6.4 汉语翻译

    1.题目

缩 写

当 Little White A 遇到 Little White B:
       Little White A:(吃惊)!
       Little White B:?
       Little White A:你知道“SHDC”?难以置信!
       Little White B:你是 Little White! Little White 是你!你指的“SHDC”是什么?
       Little White A:等等,我是指“Super Hard-disc Drive Cooler”。
       Little White B:我以为是“Spade Heart Diamond Club”。真是鸭同鸡讲话-_-// 
       Little White A:鸭,鸡,晕!

——摘自 qmd of Spade6,CC98 论坛。

我们经常写缩写。如 IBM 是 International Business Machines 的缩写。一个名字通常包含多个单词。一个单词以一个大写字母打头(“A”~“Z”),后面不跟或跟多个小写字母(“a”~“z”)。缩写是由每个单词的首字母组成。
       现在,给出两个名字,要求你说出这两个名字的缩写是否相同。

2.输入描述

标准输入将包含多个测试案例。输入的第一行是一个整数 T,代表测试案例的个数。然后,是 T 组测试案例。
        一组测试案例有四行。
        第一行是一个整数 N(1≤N≤5),表示第一个名字中单词的个数。
        第二行显示了第一个名字。
        第三行是一个整数 M(1≤M≤ 5),表示第二个名字中单词的个数。
        第四行显示了第二个名字。
       每个名字由多个单词组成,单词间用一个空格分开。每个单词的长度少于 10 个。每个单词的第一个字母是大写字母,其余字母是小写字母。

3.输出描述

结果应为标准输出。每个测试案例输出一行。如果两个名字的缩写相同,则输出“SAME”,否则,输出“DIFFERENT”。

4.输入样例


             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

5.输出样例

SAME 
             SAME 
             DIFFERENT

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{ string s[5],t[5];int d,m,n,i,j;cin>>d;for(i=0;i<d;i++){cin>>m;for(j=0;j<m;j++){cin>>s[j];}cin>>n;for(j=0;j<n;j++){cin>>t[j];}if(m!=n){cout<<"DIFFERENT"<<endl;continue;}else{int num=0;for(j=0;j<n;j++){if(s[j][0]==t[j][0]){num++;}}if(num==n){cout<<"SAME"<<endl;}else{cout<<"DIFFERENT"<<endl;}}}return 0;
} 

2.6.5 解题思路

本题是比较两个缩写词是否相同,而缩写词又是从一个包含多个单词的名字中合成的。每次读入一个单词,然后取出它的第一个字母,连接在字符串上,就组成了一个缩写词。
         本题的难点在单词的读取控制上,对于输入数据的控制,是 ACM 竞赛中考查的一个重要方面。
         另外,大家可以试试,使用 printf 输出比使用 cout 输出快很多。

2.6.6  参考答案

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{  string s,ssa,ssb; int t,n,m; cin>>t; for(int i=0;i<t;i++) { cin>>n; for(int j=0;j<n;j++) { cin>>s; ssa=ssa + s[0]; } cin>>m; for(int k=0;k<m;k++) { cin>>s; ssb=ssb + s[0]; } if(ssa.compare(ssb)==0)//相等返回 0,大于返回 1,小于返回-1 //cout<<"SAME"<<endl; printf("SAME\n"); else //cout<<"DIFFERENT"<<endl; printf("DIFFERENT\n"); ssa=""; ssb=""; }return 0;
} 

2.6 Abbreviation( 缩 写)相关推荐

  1. 商 务 英 语 常 用 缩 略 语 表

    商 务 英 语 常 用 缩 略 语 表 缩 写 全 称 中 文 a accepted 承兑 A&C addenda and corrigenda 补遗和勘误 A.C.V actual cash ...

  2. ffmpeg的操作参数

    ffmpeg 常用命令汇总_kingvon_liwei的博客-CSDN博客_ffmpeg Print help / information / capabilities: -L             ...

  3. 转贴:Friends 第一季英文学习整理:102

    [102]The One With The Sonogram At The End No.2 The One With the Sonogram at the End 上集说道Rach 和Ross 分 ...

  4. C#命名规则、开发习惯和风格

    1.     文件命名组织 1-1文件命名 1.        文件名遵从Pascal命名法,无特殊情况,扩展名小写. 2.        使用统一而又通用的文件扩展名: C# 类 .cs 1-2文件 ...

  5. sql server 日期

    一.时间函数 在使用存储过程,sql函数的时候,会遇到一些对时间的处理.比如时间的获取与加减.这里就用到了sql自带的时间函数.下面我列出这些函数,方便日后记忆,使用. --getdate 获取当前时 ...

  6. 使用sendfile()让数据传输得到最优化,TCP_CORK、TCP_DEFER_ACCEPT和TCP_QUICKACK优化网络...

    当今国互联网的飞速发展让人们获益匪浅,同时人们对于互联网 的期望值也变得越来越高.这就形成了一个矛盾,虽然互联网的 发展已经是相当迅猛的了,但是人们还是期望从服务器到客户终 端的文件传输的速度能够比现 ...

  7. 切换器黑屏_机房的KVM切换器是什么,故障如何解决?

    在服务器机房的机架不便于存放多个显示器和键盘的空间里,KVM切换器起着重要的作用.KVM切换器能从本地或远程监视与控制多个计算机与服务器,由键盘.鼠标和显示屏组成的KVM控制台是最方便和经济的理想解决 ...

  8. server日期函数

    server日期函数 SQLServer时间日期函数详解,SQLServer,时间日期, 1.      当前系统日期.时间 select getdate() 2. dateadd      在向指定 ...

  9. sqlserver 时间格式函数详细

    一.时间函数 在使用存储过程,sql函数的时候,会遇到一些对时间的处理.比如时间的获取与加减.这里就用到了sql自带的时间函数.下面我列出这些函数,方便日后记忆,使用. --getdate 获取当前时 ...

  10. vue-cli教程(一)

    1.安装vue-cli 再安装完成npm之后,利用npm安装vue-cli,全局安装:npm insall -g vue-cli.倘若npm速度慢,建议替换为cnpm(https://npm.taob ...

最新文章

  1. ThickBox 3.1参数详解(转)
  2. JAVA面向对象的特征
  3. 一个可以检测网络内主机类型的脚本
  4. 面试官问:平常你是怎么对 Java 服务进行调优的?
  5. copyleft_什么是copyleft?
  6. php框架大全图解_PHP框架汇总 - 鱼煎的个人空间 - OSCHINA - 中文开源技术交流社区...
  7. android百度定位没反应,百度定位回调无反应,第一次能回调到数据,第二次无反应...
  8. 颓废了1年+,今天开始勤(tui)奋(fei)啦
  9. python爬取千图网高清图
  10. 基于模板匹配的螺母检测(计算机视觉实验)
  11. 微信小程序 - 点击事件传递参数(简单详细)
  12. 【步步到位】mysql安装教程 8.0.26
  13. 软件工程中的数据流图
  14. mp4视频怎么转换成华为P10手机适配的分辨率
  15. 向技术大牛进击!!——计算机编程进修动员大会
  16. MATLAB设置图片输出的尺寸大小与字体(适用科研论文)
  17. vmware虚拟机中ubuntu如何连接校园网netkeeper
  18. 时延、时间带宽积、RTT、利用率
  19. 2022年9月全球数字安全最新新闻汇总
  20. JAVA静态代理与动态代理(JDK和CGLIB)

热门文章

  1. 本悟法师:信仰,让孤独走开
  2. vmware虚拟机连不上服务器,VMware虚拟机nat模式连不上网怎么办
  3. sql 远程过程调用失败
  4. 在Harvester上安装windows sever 2012 r2
  5. 人人商城 重复授权问题
  6. 手机信息通知标为已读实现原理_27条iPhone苹果(附iPhoneX)手机使用技巧,你用过多少条?...
  7. 三级等保 mysql8.0.24密码策略设置
  8. PC传输图片到Hololens
  9. 工作之外的闲暇时光(玩魔方)
  10. 美团服务器不稳定号码保护,美团外卖怎么开启号码保护 隐藏自己手机号这么设置...