《ACM书中题目》Z
来源:互联网 发布:马小丝的淘宝 编辑:程序博客网 时间:2024/06/11 17:01
- 原题
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”.
理解&思路
给定一些英文单词,判断这些单词的缩写是否一致。
既然只让判断缩写,就不必把全部字符读入,只需要建立两个字符串,每个字符串只存入两个数据的首字母,最后比较两个字符串是否一致。AC代码
#include<bits/stdc++.h>using namespace std;int main(){ string a,b,c; int i,j,k,n,m,p; cin>>p; for(i=0;i<p;i++) { cin>>n; for(j=0;j<n;j++) { cin>>a; b+=a[0]; } cin>>m; for(j=0;j<m;j++) { cin>>a; c+=a[0]; } if(b.compare(c)==0) cout<<"SAME"<<endl; else cout<<"DIFFERENT"<<endl; b=""; c=""; }}
- 总结
利用compare()函数比较两个字符串是否相等比较方便。
以题中为例
b.compare(c)
if b>c return 1;
if b==c return 0;
if b
- 《ACM书中题目》Z
- 《ACM程序设计》书中题目―Z
- acm书中题目 z-26
- 《ACM程序设计》书中题目--problem z
- ACM程序设计 书中题目Z
- 《ACM程序设计》书中题目Z-26
- 《ACM程序设计》书中题目 Z
- ACM书中题目——Z
- 《ACM程序设计》书中题目 Z
- 《ACM程序设计》书中题目 Z
- acm程序设计书中题目z
- 《ACM程序设计》书中题目z
- 《ACM程序设计》书中题目Z(英文缩写)
- ACM书中的题目 Z-26
- ACM程序设计书中题目--z(两组字符串中单词的首字母是否相同)
- 《ACM程序设计》书中题目Z 第二十六题 判断首字母缩写是相同
- ACM程序设计书上题目Z
- ACM书中题目 K
- Word Search
- Android 非静态内部类/匿名类引起的内存泄漏
- 测试基础---测试策略与方法02
- unix/linux 系统实现多个进程监听同一个端口
- 欢迎使用CSDN-markdown编辑器
- 《ACM书中题目》Z
- C++函数重写(override)与函数重载(overload)
- SQL server 实验五 (sql 查询语句)
- NLTK之搜索文本的相关入门函数(二)
- 设计模式–单例模式
- LightOJ1370Bi-shoe and Phi-shoe(欧拉函数)
- 文章标题
- redis简介
- 函数模板和普通函数的抉择