zoukankan      html  css  js  c++  java
  • USACO Section 1.3 Calf Flac

    最后一个测试数据恶心的,看了各种优化,不过我还是不知道为什么我第一次的代码会超时,现在这个是把以前的数组过滤掉标点,然后记录原来位置,有点像北航那个字符串删除的题,不过感觉也没有优化啥,看了下测试数据,居然有随机字符串,还有一个JAVA的代码,C代码,最后一个超恶心的重复大数据

    /*	
      ID:linyvxi1
      PROB:calfflac
      LANG:C++
    */
     
    #include <stdio.h>
    #include <string.h>
    #define MAX	20005
    
    int n=0,m=0,max=0,left,right;
    int pos[MAX];
    char str1[MAX],str2[MAX],ch;
    
    void check(int L,int R)
    {
    	while(L>=1&&R<=m){
    		if(str2[L]==str2[R]){
    			L--;
    			R++;
    		}
    		else	break;
    	}
    	if(R-L-1>max){
    		max=R-L-1;
    		left=pos[L+1];
    		right=pos[R-1];
    	}
    }
    
    int main()
    {
    	freopen("calfflac.in","r",stdin);
    	freopen("calfflac.out","w",stdout);
    
    	memset(str1,'\0',sizeof(str1));
    	memset(str2,'\0',sizeof(str2));
    
    	while(scanf("%c",&ch)!=EOF){
    		str1[++n]=ch;
    	}
    
    	int i;
    	for(i=1;i<=n;i++){
    		if((str1[i]>='a'&&str1[i]<='z')||(str1[i]>='A'&&str1[i]<='Z')){
    			m++;
    			if(str1[i]>=97)	str2[m]=str1[i]-32;
    			else str2[m]=str1[i];
    			pos[m]=i;
    		}
    	}
    
    	for(i=1;i<=n;i++){
    		check(i-1,i+1);
    		check(i,i+1);
    	}
    
    	printf("%d\n",max);
    	for(i=left;i<=right;i++)
    		printf("%c",str1[i]);
    	putchar('\n');
    }
    

      

  • 相关阅读:
    Python打包之pyinstaller
    Python关于Pyqt
    Python撰写mail
    后台管理左侧菜单
    全选反选以及取消
    模态对话框
    Spark2.3.1版本全分布模式的安装与部署
    Kafka消息格式及多版本支持
    2019-11-18-plot作图
    剑指Offer-知识迁移能力53-59
  • 原文地址:https://www.cnblogs.com/yangce/p/2230458.html
Copyright © 2011-2022 走看看