zoukankan      html  css  js  c++  java
  • 【模拟】Gym

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

    #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;
    }
  • 相关阅读:
    poj 1149 最大流
    poj 3281 最大流建图
    lightoj 1300 边双联通分量+交叉染色求奇圈
    lightoj 1291 无向图边双联通+缩点统计叶节点
    lightoj 1063 求割点
    lightoj 1026 无向图 求桥
    lightoj 1407 2-sat
    lightoj 1251 (Two_Sat)
    hdu 4681 最长公共子序列+枚举
    OD汇编需要标签
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/7163361.html
Copyright © 2011-2022 走看看