让你把所有的“连续的仅有首字母大写的”词组用缩写表示,并且在后面用括号注明原词组。

#include<cstdio>
#include<cstring>
using namespace std;
char s[130];
bool iszimu(char c){
return ((c>='A' && c<='Z') || (c>='a' && c<='z'));
}
bool isbig(char c){
return (c>='A' && c<='Z');
}
bool issmall(char c){
return (c>='a' && c<='z');
}
bool check(int l,int r){
if(r-l+1==1){
return 0;
}
if(!isbig(s[l])){
return 0;
}
for(int i=l+1;i<=r;++i){
if(!issmall(s[i])){
return 0;
}
}
return 1;
}
void print(int l,int r){
for(int i=l;i<=r;++i){
putchar(s[i]);
}
}
void prin2(int l,int r){
for(int i=l;i<=r;++i){
if(isbig(s[i])){
putchar(s[i]);
}
}
printf(" (");
for(int i=l;i<=r;++i){
putchar(s[i]);
}
putchar(')');
}
int main(){
freopen("abbreviation.in","r",stdin);
freopen("abbreviation.out","w",stdout);
while(gets(s)){
int n=strlen(s),sta,cnt=0,end=-1,Sta,End=-1;
for(int i=0;i<n;++i){
if((i==0 || !iszimu(s[i-1])) && iszimu(s[i])){
sta=i;
}
if((i==n-1 || !iszimu(s[i+1])) && iszimu(s[i])){
if(check(sta,i) && (cnt==0 || (end==sta-2 && s[end+1]==' '))){
++cnt;
if(cnt==1){
Sta=sta;
End=end;
}
}
else if(check(sta,i)){
if(cnt>=2){
print(End+1,Sta-1);
prin2(Sta,end);
}
else if(cnt==1){
print(End+1,Sta-1);
print(Sta,end);
}
cnt=1;
Sta=sta;
End=end;
}
else{
if(cnt>=2){
print(End+1,Sta-1);
prin2(Sta,end);
}
else if(cnt==1){
print(End+1,Sta-1);
print(Sta,end);
}
print(end+1,i);
cnt=0;
}
end=i;
}
}
if(cnt>=2){
print(End+1,Sta-1);
prin2(Sta,end);
}
else if(cnt==1){
print(End+1,Sta-1);
print(Sta,end);
}
print(end+1,n-1);
puts("");
}
return 0;
}

【模拟】Gym - 101190A - Abbreviation的更多相关文章

  1. 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...

  2. 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: n个序列.每个序列有4个值x,a,b,c,之后按照x=(a*x+b)%c扩展无穷项. 求每个序列各取一个数之后 ...

  3. 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...

  4. 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...

  5. 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和.C c ...

  6. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】

    C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...

  8. Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

    B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...

  9. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

随机推荐

  1. ftrace 的使用【转】

    转自:http://blog.csdn.net/wang6077160/article/details/7814279 ftrace 的使用 ftrace 在内核态工作,用户通过 debugfs 接口 ...

  2. 【bzoj4373】算术天才⑨与等差数列

    同之前那道由乃题,可以认为由乃题是这题的特殊情况…… 维护方法是同样的,维护区间和,区间平方和即可. 注意特判一个数(其实没有必要) #include<bits/stdc++.h> ; u ...

  3. 升级OS10.11系统后 Xcode6.4的变化少了个按钮 could not launch “Xcode” Xcode 插件安装

    升级OS10.11系统后 Xcode6.4的变化少了个按钮 could not launch “Xcode”  Xcode 插件安装 A:  升级10.11后Xcode 左上角模拟器选择菜单不在了   ...

  4. API(全局配置,全局API)

    全局配置 Vue.config是一个对象,包含Vue的全局配置 silent 类型:boolean 默认值:false 用法 Vue.config.silent=true 取消Vue所有的日志与警告 ...

  5. [How to] 真机调试

    1.简介 真机调试介绍. 在xcode7之前需要每年99刀的代价才能活着开发者权限并能够在真机上调试,现在如果单纯的想在真机上调是就不必花这个钱了. 2.步骤 完毕.

  6. yum安装的Apache的各种配置文件的位置

    //配置文件 /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/proxy_ajp.conf / ...

  7. 高性能网络编程(1)—accept建立连接‍(待研究)

    阿里云博客上一篇感觉还不错的文章,待研究,原文链接如下: http://blog.aliyun.com/673?spm=5176.7114037.1996646101.3.oBgpZQ&pos ...

  8. spring boot&&cloud干货系列

    接触spring boot也有些时日了,刚开始博主还想参照官方参考指南自己写一个系列的入门式的教程,包含spring boot的所有模块的用法,后来发现,有一大波优秀的系列文章和项目了,所以就没班门弄 ...

  9. ZOJ-3430

    Detect the Virus  Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Nobita found that his c ...

  10. 安装vmware+CentOS 7.4

    安装步骤 选择第一个 按tab键 空格下一行 输入 红框内容  回车 注意事项 道路不通排查过程1.ip地址2.vmware 编辑-虚拟网络编辑器3.windows 服务 vmware相关服务 要开启 ...