文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>POJ 1782 解题

POJ 1782 解题

时间:2011-05-08  来源:超级福满多

被一个破空格弄惨了,悲剧,以后还是申请一个大字符数组比较好做

#include<iostream>
#include<stdio.h>

using namespace std;

#define NOT_CONS 0 //0: not consecutive;
#define CONS 1 //1: consecutive;
#define NOT_CONS_FIRST 2 //2: not consecutive and 1st char

void init(char& in,char& last,int& lastLen,int& state){
        while(true){
                in = getchar();
                if(in==10){
                        cout<<endl;
                        continue;
                }
                else break;
        }
        last = in;
        lastLen=1;
        state=NOT_CONS_FIRST;
}

int main(){

        int state;  

        char in,last;
        int lastLen;

        //init
        init(in,last,lastLen,state);

        while(in>=0){
                in = getchar();
                if(in==10){//end situation
                        if(state==NOT_CONS_FIRST){
                                cout<<'1';
                                state=NOT_CONS;
                        }
                        if(state==NOT_CONS){
                                if(last=='1')
                                        cout<<'1';
                                cout<<last<<lastLen<<endl;
                        }else{
                                cout<<lastLen<<last<<endl;
                        }
                        //reset
                        init(in,last,lastLen,state);

                }else if(in==last){//maybe consecutive seq
                        if(state==NOT_CONS){
                                cout<<'1';//end 1
                        }
                        state = CONS;
                        if(lastLen<9){
                                lastLen++;
                        }else{
                                cout<<'9'<<last;
                                lastLen=1;
                                state=NOT_CONS_FIRST;
                        }
                }else{//last!=in not consecutive seq
                        if(state==NOT_CONS_FIRST){
                                cout<<'1';
                                state=NOT_CONS;
                        }
                        if(state==NOT_CONS){
                                if(last=='1') cout<<'1';
                                cout<<last;
                                last=in;
                                lastLen=1;
                        }else if(state==CONS){
                                cout<<lastLen<<last;
                                last=in;
                                lastLen=1;
                                state=NOT_CONS_FIRST;
                        }
                }//end else
        }//end while
        
        return 0;
}
相关阅读 更多 +
排行榜 更多 +
泡龙大闯关安卓版

泡龙大闯关安卓版

冒险解谜 下载
割草派对安卓版

割草派对安卓版

飞行射击 下载
堡垒攻防战安卓版

堡垒攻防战安卓版

飞行射击 下载