• uva123 Searching Quickly


    短小而精悍的代码,把我所学的几乎都用上了,测试数据过了,只可惜不AC,挣扎了一天了,累死啦!!!!!

    View Code
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<ctype.h>
    int cmp(const void *a,const void *b)
    {
        return strcmpi((char *)a,(char *)b);
    }
    char word[210][17],iword[51][17],st[10002];
    int main()
    {
        int itop = 0, top = 0, i = 0, j = 0, k = 1, s[10001] = {0}, t = 0, r;
        char ch;
        while(gets(iword[itop]))
        {
            if(strcmp(iword[itop],"::") == 0)
                break;
            itop++;
        }
        while((ch = getchar()) != EOF)
        {
            t++;
            if(ch != '\n')
                st[i++] = ch;
            if(ch != ' ' && ch != '\n')
                word[top][j++] = ch;
            else
            {
                word[top][j] = '\0';
                top++;
                for(r = 0;r < itop; r++)
                {
                    if(strcmpi(iword[r],word[top-1]) == 0)
                    {
                        top--;
                        break;
                    }
                }
                j = 0;
                if(ch == '\n')
                {
                    st[i++] = '\0';
                    s[k++] = t;
                }
            }
        }
        qsort(word,top,sizeof(word[0]),cmp);
        for(j = 0;j < top; j++)
        {
            int len = strlen(word[j]), x = 0;
            if(strcmpi(word[j],word[j+1]) == 0)
            {
                continue;
            }
            for(r = 0;r < k; r++)
            {
                x = 0;
                while(strstr(st+s[r]+x,word[j]) != NULL)
                {
                    char *p = strstr(st+s[r]+x,word[j]), *q;
                    x = p - st+len;
                    for(q = st+s[r];q < p; q++)    
                    {
                        if(isalpha(*q))
                            putchar(tolower(*q));
                        else
                            putchar(*q);
                        
                    }
                    for(;q < p+len; q++)
                        putchar(toupper(*q));
                    for(;*q != '\0';q++)
                    {
                        if(isalpha(*q))
                            putchar(tolower(*q));
                        else
                            putchar(*q);
                        
                    }
                    puts("");
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    ITIL 4Foundation认证
    Linux服务器安全之 fail2ban的安装与配置
    Linux的常用基础命令
    jQuery源码学习(2):选择器初窥
    jQuery源码学习(1):整体架构
    从字符串拼接看JS优化原则
    理解函数作用域与闭包
    JavaScript DOM节点操作总结
    函数声明与函数表达式、变量提升
    CSS长度单位详解
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2605112.html
Copyright © 2020-2023  润新知