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

#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. Java线程总结(一)

    首先,先贴上一个简单的线程实例: public class MyThread extends Thread{ @Override public void run(){ try { for (int i ...

  2. 浅谈Trigger(SimpleTrigger&CronTrigger)

     1.Trigger是什么 Quartz中的触发器用来告诉调度程序作业什么时候触发,即Trigger对象是用来触发执行job的.  2.Quartz中的Trigger  3.触发器通用属性: JobK ...

  3. Part2-HttpClient官方教程-Chapter5-流利的API

    5.1. 易于使用的Facade API 使用之前注意引入相应Jar包或者Maven依赖 <dependency> <groupId>org.apache.httpcompon ...

  4. ubuntu gnome桌面秀

    之前装的是ubuntu14.10gnome版的 然后一路升级成15.04,到今天的15.10 最后发现现在的gnome桌面已经非常适合我的工作了 先放一张图,这是我的桌面 原来使用ubuntu15.0 ...

  5. 金融分析二:Matplotlib模板

    Matplotlib:绘图和可视化 Matplotlib是一个强大的Python绘图和数据可视化的工具包. 安装方法:pip install matplotlib 引用方法:import matplo ...

  6. OGRECave [www]

    OGRECave https://github.com/OGRECave

  7. oracle to_char 返回毫秒级

    select to_char(systimestamp,'yyyy-mm-dd hh24:mi:ssxff') time1, 关键在 systimestamp

  8. JS面试题第一弹

    1.javascript的typeof返回哪些数据类型  alert(typeof [1, 2]); //object     alert(typeof 'leipeng'); //string   ...

  9. 【LabVIEW技巧】代码块快速放置

    前言 之前的文章中介绍了如何使用QuickDrop来实现快速代码放置,今天我们来详细的聊一下如何进行代码块的快速放置. 正文 LabVIWE程序设计中,我们在架构层级总是进行重复性的编写.举一个例子: ...

  10. mybatis-plus的学习

    1.mybatisplus 提供了比较齐全的crud即增删改查,不需要在mapper.xml里写sql可以直接调用 原文链接:http://blog.csdn.net/u014519194/artic ...