zoukankan      html  css  js  c++  java
  • 《算法竞赛入门经典》(刘汝佳)——字符串(基础)

    1:WERTYU

    poj 2538 WERTYU

    #include<stdio.h>
    int main()
    {
        char c;
        char s[]="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
        while((c=getchar())!=EOF)
        {
            int i;
            for(i=0;s[i]&&s[i]!=c;i++);
            if(s[i])
                printf("%c",s[i-1]);
            else 
                printf("%c",c);
        }
        return 0;
    }
    View Code

    2:TeX括号

     poj 1488 TEX Quotes

    #include<stdio.h>
    int main()
    {
        char c;
        int k=1;
        while((c=getchar())!=EOF)
        {
            if(c=='"'){
                if(k>0)printf("``");
                else printf("''");
                k=-k;
            }
            else
                printf("%c",c);
        }
        return 0;
    }
    View Code

    3:周期串

    poj 2406 Power Strings

    #include<stdio.h>
    #include<string.h>
    char s[1000005];
    int main()
    {
    
        while(scanf("%s",s)!=EOF)
        {
            if(strcmp(s,".")==0)break;
            int len=strlen(s);
            for(int i=0;i<len;i++)
            {
                if(len%(i+1)==0)
                {
                    int flag=0;
                    for(int j=i;j<len;j++)
                    {
                        if(s[j]!=s[j%(i+1)])
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        printf("%d
    ",len/(i+1));
                        break;
                    }
                }
            }
        }
        return 0;
    }
    View Code
    一道又一道,好高兴!
  • 相关阅读:
    虚树
    最小树形图
    分块
    斜率优化
    单调队列优化DP
    树套树
    2-SAT
    莫队
    单调队列
    单调栈
  • 原文地址:https://www.cnblogs.com/laiba2004/p/3585024.html
Copyright © 2011-2022 走看看