【模拟】Gym - 101190A - Abbreviation
让你把所有的“连续的仅有首字母大写的”词组用缩写表示,并且在后面用括号注明原词组。
- #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的更多相关文章
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- 【模拟】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扩展无穷项. 求每个序列各取一个数之后 ...
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...
- 【模拟】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 ...
- 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 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 ...
- 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 ...
- Gym 100646 Problem C: LCR 模拟题
Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...
随机推荐
- 制作Solaris系统的USB启动盘
制作方法: 1. wget http://192.168.2.5/surefiler-installer/2011-12-09/devel-2011.12.9.tgz 2. cd /root tar ...
- hdu 1281 棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 1599 find the mincost route (最小环与floyd算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...
- JSOI2018简要题解
来自FallDream的博客,未经允许,请勿转载,谢谢. 有幸拜读到贵省的题目,题的质量还不错,而且相比zjoi可做多了,简单发一下题解吧. 还有就是,怎么markdown在博客园上的代码这么丑啊 「 ...
- [CTF技巧]批量连接SSH批量执行命令
https://files.cnblogs.com/files/nul1/autossh1.3.jar.zip 下载下来以后直接将后缀去除就好了. 比赛的时候可以批量写一个不死马然后你懂的. Linu ...
- Linux进程调度与源码分析(二)——进程生命周期与task_struct进程结构体
1.进程生命周期 Linux操作系统属于多任务操作系统,系统中的每个进程能够分时复用CPU时间片,通过有效的进程调度策略实现多任务并行执行.而进程在被CPU调度运行,等待CPU资源分配以及等待外部事件 ...
- Tabular DataStream protocol 协议
Tabular DataStream protocol 协议 Freetds 创建过程 https://wenku.baidu.com/view/2076cbfaaef8941ea76e0576.ht ...
- BZOJ 3656: 异或 (组合数取模 CRT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3656 大意:经过一通推导,问题变成求\[\binom N M \mod P\],其中N,M<= ...
- java数组面试题
一维数组可以写成:int[ ]x 或者int x[ ]: 二维数组可以写成:int[ ] y [ ] 或者int y[ ][ ] 或者int [ ][ ]y 面试题如下: 声明数组int[ ...
- js中常用的数组方法
在数组的尾部增加或删除某个元素:push() 和 pop() push() : 在数组的尾部追加一个或多个元素,并返回数组的长度 pop():在数组的尾部删除一个元素,并返回被删除项 var arr ...