• 本地CodeForces


    #include <stdio.h>
    #include <string.h>
    
    #define MAXCMDLEN    200
    #define MAXLINELEN    10000
    
    int  LastDiv,NewDiv,MaxPage;
    int  Div,IndexCnt;
    char Cmd[MAXCMDLEN],Line[MAXLINELEN],Name[5],Png[MAXCMDLEN];
    int  i,j,k,l,p,Len;
    FILE *fIndex,*fTemp,*fExist,*fWrite;
    
    void AddToIndex(FILE *file,int i,char *str)
    {
        fprintf(file,"\t\t<td><a href=problemset/%d%s>%d%s</a></td>\n",i,str,i,str);
        ++IndexCnt;
        if((IndexCnt&7)==0)
        {
            fprintf(file,"\t</tr><tr>\n");
        }
    }
    
    void MakeHtml(int i,char *str)
    {
        sprintf(Cmd,"problemset/%d%s",i,str);
        fWrite=fopen(Cmd,"w");
        sprintf(Cmd,"grep -n \"ttypography\\\"\" temp > linenum");
        system(Cmd);
        fTemp=fopen("linenum","r");
        fscanf(fTemp,"%d",&Len);
        fclose(fTemp);
        fTemp=fopen("temp","r");
        fprintf(fWrite,"<html>\n\t<body>\n<LINK charset=\"utf-8\" href=\"src/style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n\n");
        for(l=0;l<Len;++l)
        {
            fgets(Line,MAXLINELEN,fTemp);
        }
        Len=strlen(Line);
        for(l=0;l<Len;++l)
        {
            if(l<Len-30)
            {
                if(Line[l]=='s'&&Line[l+1]=='r'&&Line[l+2]=='c')
                {
                    fprintf(fWrite,"src=\"");
                    l+=26;
                    for(p=0;Line[l]!='"';++l,++p)
                    {
                        Png[p]=Line[l];
                    }
                    Png[p]='\0';
                    fprintf(fWrite,"%s\"",Png);
                    sprintf(Cmd,"wget -q http://codeforces.ru/%s -O problemset/%s",Png,Png);
                    system(Cmd);
                }
                else
                {
                    fprintf(fWrite,"%c",Line[l]);
                }
            }
        }
        fprintf(fWrite,"\n");
        fprintf(fWrite,"\t</body>\n</html>");
        fclose(fWrite);
        fclose(fTemp);
    }
    
    int ProcessName(int i,char *str)
    {
        sprintf(Cmd,"problemset/%d%s",i,str);
        fExist=fopen(Cmd,"r");
        if(fExist==NULL)
        {
            printf("Try to get %d%s.........",i,str);
            sprintf(Cmd,"curl -I -s http://codeforces.com/problemset/problem/%d/%s | grep Content-Length > temp",i,str);
            system(Cmd);
            fTemp=fopen("temp","r");
            fscanf(fTemp,"%*s %d",&Len);
            fclose(fTemp);
            if(Len!=0)
            {
                sprintf(Cmd,"wget -q http://codeforces.com/problemset/problem/%d/%s -O temp",i,str);
                system(Cmd);
                MakeHtml(i,str);
                AddToIndex(fIndex,i,str);
                printf("OK!\n");        
            }
            else
            {
                printf("Error,It's not exist!\n");
                return -1;
            }
        }
        else
        {
            AddToIndex(fIndex,i,str);
            fclose(fExist);
        }
        return 0;
    }
    
    void MakeProblemSet()
    {
        system("touch ProblemSetIndex && rm ProblemSetIndex");
        fIndex=fopen("ProblemSetIndex","w");
        fprintf(fIndex,"<html>\n\t<body>\n\n<h1 align=center>CodeForces</h1><p>\n<table align=center width=\"90%\">\n\t<tr>\n");
        for(i=LastDiv;i<=NewDiv;++i)
        {
            if(i==177)
            {
                for(j=0;j<7;++j)
                {
                    for(k=1;k<=2;++k)
                    {
                        sprintf(Name,"%c%d\0",j+'A',k);
                        ProcessName(i,Name);
                    }
                }
            }
            else if(i==178)
            {
                for(j=0;j<6;++j)
                {
                    for(k=1;k<=3;++k)
                    {
                        sprintf(Name,"%c%d\0",j+'A',k);
                        ProcessName(i,Name);
                    }
                }
            }
            else if(i==207)
            {
                for(j=0;j<4;++j)
                {
                    for(k=1;k<=3;++k)
                    {
                        sprintf(Name,"%c%d\0",j+'A',k);
                        ProcessName(i,Name);
                    }
                }
                for(k=4;k<=9;++k)
                {
                    sprintf(Name,"%c%d\0",'D',k);
                    ProcessName(i,Name);
                }
            }
            else
            {
                for(j=0;j<26;++j)
                {
                    sprintf(Name,"%c\0",j+'A');
                    if(ProcessName(i,Name)==-1)
                    {
                        break;
                    }
                }
            }
        }
        fprintf(fIndex,"\t</tr>\n</table>\n\n\t</body>\n</html>");
        fclose(fIndex);
    }
    
    char *strrev(char *str)
    {
        char *p1,*p2;
        for(p1=str,p2=str+strlen(str)-1;p2>p1;++p1,--p2)
        {
            *p1^=*p2;
            *p2^=*p1;
            *p1^=*p2;
        }
        return str;
    }
    
    void MakeForNoSoul()
    {
        IndexCnt=0;
        system("touch ForNoSoul && rm ForNoSoul");
        fIndex=fopen("ForNoSoul","w");
        fprintf(fIndex,"<html>\n\t<body>\n\n<h1 align=center>CodeForces For NoSoul</h1>\n");
        fprintf(fIndex,"<table align=center width=\"90%\">\n\t<tr>\n");
        for(i=1;i<=MaxPage;++i)
        {
            sprintf(Cmd,"wget -q http://codeforces.com/problemset/page/%d?order=BY_SOLVED_DESC -O temp",i);
            system(Cmd);
            fTemp=fopen("temp","r");
            for(j=0;j<700;++j)
            {
                fgets(Line,MAXLINELEN,fTemp);
            }
            while(fgets(Line,MAXLINELEN,fTemp)!=NULL)
            {
                Len=strlen(Line);
                if(Len>=15)
                {
                    if(Line[Len-6]=='i'&&Line[Len-5]=='d'&&Line[Len-3]=='>')
                    {
                        fgets(Line,MAXLINELEN,fTemp);
                        fgets(Line,MAXLINELEN,fTemp);
                        Len=strlen(Line);
                        for(k=0,j=Len-3;Line[j]!=' ';++k,--j)
                        {
                            Name[k]=Line[j];
                        }
                        Name[k]='\0';
                        strrev(Name);
                        sprintf(Cmd,"/home/nosoul/NoSoul.Love/MyProjects/MyCode/CodeForces/%s.c",Name);
                        fExist=fopen(Cmd,"r");
                        if(fExist==NULL)
                        {
                            printf("Add %s to NoSoul Index.\n",Name);    
                            sscanf(Name,"%d%s",&Div,Name);
                            AddToIndex(fIndex,Div,Name);
                        }
                    }
                }
            }
            fclose(fTemp);
        }
        fprintf(fIndex,"\t</tr>\n</table>\n\n\t</body>\n</html>");
        fclose(fIndex);
    }
    
    int main(int argc,char *argv[])
    {
        fExist=fopen("problemset/src/style.css","r");
        if(fExist==NULL)
        {
            system("mkdir problemset && mkdir problemset/src problemset/renderer");
            system("wget -q http://codeforces.ru/static/combine/ec1325e741305c9a1a85151d0f3e0565_9a4e89dff55c2bd439f2378c20e3710f.css -O problemset/src/style.css");
        }
        else
        {
            fclose(fExist);
        }
        int i;
        if(argc>1)
        {
            for(i=1;i<argc;++i)
            {
                if(strcmp(argv[i],"Set")==0)
                {
                    LastDiv=atoi(argv[i+1]);
                    NewDiv=atoi(argv[i+2]);
                    printf("Start Make ProblemSet...\n");
                    MakeProblemSet();
                    system("rm linenum");
                    printf("End Make ProblemSet.\n");
                    i+=2;
                }
                else if(strcmp(argv[i],"NoSoul")==0)
                {
                    MaxPage=atoi(argv[i+1]);
                    printf("Start Make For NoSoul...\n");
                    MakeForNoSoul();
                    printf("End Make For NoSoul.\n");
                    ++i;
                }
            }
        }
        system("rm temp");
        return 0;
    }

     repo:https://github.com/NoSoul/LocalCodeForces

  • 相关阅读:
    vc 网络编程(socket)
    《精通Windows API-函数、接口、编程实例》——第4章文件系统
    WindowsAPI使用详解——GetVersion|GetVersionEx 获取操作系统版本和名称
    Windows编程 鼠标
    Windows 编程 键盘
    Windows编程 Windows程序的生与死(下)
    二叉查找树——A1043.Is it a Binary Search Tree(25)
    Springboot + ElasticSearch 构建博客检索系统
    树的遍历——A1053.Path of Equal Weight(30) 只可DFS不可BFS
    树的遍历——A1004.Counting Leaves(30) 给出一棵树,问每一层有多少叶子节点(可DFS也可BFS)
  • 原文地址:https://www.cnblogs.com/NoSoul/p/3013067.html
Copyright © 2020-2023  润新知