悲剧文本

这个是静态链表,基于数组实现的链表。最开始完全不能理解,但是之后不断查资料,大概有个模型,通过两个数组,一个记录数据,一个记录应该输出的顺序,然后由顺序这个数组进行一个循环,然后再输出,所以这一道题目就可以使用这个性质;当遇到[将光标cur记为0;]则为最后的last。然后这些顺序呢记录到顺序的数组

#include <cstdio>  
#include <cstring>  
char s[1100047];  
int hash[247];  
int main()  
{  
    __int64 n;  
    while(~scanf("%I64d",&n) && n)  
    {  
        getchar();  
        gets(s);  
        __int64 len = strlen(s);  
        memset(hash,0,sizeof(hash));  
        __int64 i, star = 0, ans = 0, diff = 0;  
        for(i = 0; i < len; i++)  
        {  
            ++hash[s[i]];//映射值+1  
            if(hash[s[i]] == 1)//如果是第一次出现  
            {  
                diff++;//不同字母数+1  
                if(diff > n)//如果超过n个不同字母  
                {  
                    while(--hash[s[star++]] > 0);//起点向右挪动 直到消去一个字母                    
                    diff--;//不同字母数返回正常取值  
                }  
            }  
            int LEN = i-star+1;//得到此时的串长度  
            ans = ans > LEN?ans:LEN;//保存最大值  
        }  
        printf("%I64d
",ans);  
    }  
    return 0;  
}  

  

原文地址:https://www.cnblogs.com/yintoki/p/5676857.html