Z
来源:互联网 发布:数据魔方下载 编辑:程序博客网 时间:2024/04/30 14:37
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
SAMESAMEDIFFERENT
看输入的每组的第一个字母是否相同,相同输出SAME 否则DIFFERENT
分析:
把 字符串第一个字母放到数组中,然后进行比较
代码:
#include <bits/stdc++.h>using namespace std;int main(){ int i,j,t,m,q,w; string s; char f,a[10],b[10]; while(cin>>m) { for(i=0;i<m;i++) { cin>>q; for(t=0;t<q;t++) { cin>>s; a[t]=s[0]; } cin>>w; for(t=0;t<w;t++) { cin>>s; b[t]=s[0]; } if(q!=w) { cout<<"DIFFERENT"<<endl; } else { for(j=0;j<q;j++) if(a[j]!=b[j]) { cout<<"DIFFERENT"<<endl; break; } if(j==q) cout<<"SAME"<<endl; } } }}
感受:就是一开始用while,老是过不了,后来改成了for,唉连个循环都不会了
- z
- z
- Z
- Z
- Z
- Z
- Z
- Z
- [z]能笑吗?
- ping[z]
- 初吻z
- Z-index
- Z字型
- Ctrl + Z
- z-index
- Z - Atlantis
- awk --z
- 程序员z
- table的td如何设置overflow:scroll
- Spark Scala 二次排序
- ALSA(Advanced Linux Sound Architecture)声卡编程介绍及实例
- Java设计模式之建造者模式
- 打印输入的内容并添加行号
- Z
- Django框架及MySQL安装配置
- POJ:1664 放苹果(递归,思维)
- 最少拦截系统
- Linux线程操作
- ffmpeg--http
- Ubuntu16.04安装后可能要做的各种事01
- 进制
- 关于wordpress设置固定链接后文章出现404的解决办法