p2240_模拟.cpp

来自「高手写的所有acm例程 在acm.zju.edu.cn 上的题目的例程」· C++ 代码 · 共 40 行

CPP
40
字号
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

//#define DEBUG

#ifdef DEBUG
#define cin fin
#define cout fout
ifstream fin ("input");
ofstream fout ( "p.out" );
#endif

main ()
{
     string  Str;
     char    Data [10000];
     while ( cin.getline(Data,sizeof(Data)) ) {
           Str = (string) Data;
           int len = Str.length () , i , j;
           for ( i = 0; i < len; i = j ) {
               for ( j = i + 1; j < len && j - i < 9 && Str [j] == Str [i]; j ++ );
               if ( j - i > 1 ) {
                    cout << j - i << Str [i];
                    continue;
               }
               for ( j = i + 1; j < len && Str [j] != Str [j - 1]; j ++ );
               if ( j < len && Str [j] == Str [j - 1] ) j --;
               cout << '1';
               for ( ; i < j; i ++ ) {
                     cout << Str [i];
                     if ( Str [i] == '1' ) cout << '1';
               }
               cout << '1';
           }
           cout << endl;
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?