众所周知,我们通常用一个单词的首字母组成的字符串来代替一个很长的英文名称,例如:ACM是“Association for Computing Machinery”的缩写。现在我们给出一些单词序列,要求按以下规则求出该单词序列的缩写。(缩写有可能是空的)
1.凡是字母个数小于等于2的单词不要。
2.“and”、“for”、“the”这三个单词不要(包括大小写的情况)。
3.除1、2点外的单词取首字母的大写形式按顺序连起来。
输入格式
第一行为一个整数n,表示要求的单词缩写的个数。(n<=100)
接下来n行,每行一个长度小于100的单词序列,每个单词都是由大写或小写字母组成,每个单词之间有一个空格。
输出格式
输出n行,每行为对应的单词缩写。
输入/输出例子1
输入:
5
Association for Computer Machinery
Institute of Electricaland Electronics Engineers
SUN YAT SEN UNIVERSITY
The Lord of the Rings
netease
输出:
ACM
IEEE
SYSU
LR
N
样例解释
无
#include<bits/stdc++.h>
using namespace std;
int n,len;
string s,t;
string c(string str)
{
string bi="";
for(int k=0;k<str.size();k++)
{
if(str[k]>='a'&&str[k]<='z')
str[k]=str[k]-'a'+'A';
bi=bi+str[k];
}
return bi;
}
int main(){
cin>>n;
getline(cin,s);
for(int i=1;i<=n;i++){
getline(cin,s);
len=s.size();
s=c(s);
t="";
for(int j=0;j<len;j++){
if(s[j]>='A'&&s[j]<='Z')
t=t+s[j];
else{
if(t.size()>2&&t!="AND"&&t!="THE"&&t!="FOR")
cout<<t[0];
t="";
}
}
if(t.size()>2&&t!="AND"&&t!="THE"&&t!="FOR")
cout<<t[0];
cout<<endl;
}
return 0;
}