Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

通过代码参考!!

Posted by seedeed at 2012-04-09 20:54:38 on Problem 1782
#include "cstdio"
#include "cstring"
class List
{
    private:
    char buffer[1000];
    int index;
    public:
    List()
    {
        index=0;
    }
    void put(char ch)
    {
        buffer[index++]=ch;
    }
    void clear()
    {
        index=0;
    }
    void print()
    {
        if(index==0) return;
        buffer[index]=0;
        putchar('1');
        for(int i=0;buffer[i];i++)
        {
            if(buffer[i]=='1') putchar('1');
            putchar(buffer[i]);
        }
        putchar('1');
    }
};
typedef struct
{
    char character;
    int count;
    void print()
    {
        printf("%d%c",count,character);
    }
}Code;
Code codes[2000];
int clen;
void put(char ch)
{
    if(clen>0&&ch==codes[clen-1].character&&codes[clen-1].count<9)
    {
        codes[clen-1].count++;
    }
    else
    {
        codes[clen].character=ch;
        codes[clen].count=1;
        clen++;
    }
}
int main()
{
    char buffer[2000];
    int i,len;
    List list;
    while(gets(buffer)!=NULL)
    {
        if(buffer[0]==0) 
        {
            puts("");
            continue;
        }
        len=strlen(buffer);
        clen=0;
        for(i=0;i<len;i++)
            put(buffer[i]);
        for(i=0;i<clen;i++)
        {
            if(codes[i].count>1)
            {
                list.print();
                list.clear();
                codes[i].print();
            }
            else list.put(codes[i].character);
        }
        list.print();
        list.clear();
        puts("");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator