Sicily 1639. Run Length Encoding

相信无论是谁看了都觉得是水题的一道题,但事实上我生生RF(极度少见的错误类型)了3次,原因在于我是先逐步构造字符串再更新字符串长度的,(怀疑)数据可能会出现longlong类型个数的字符,此时我使用的string构造函数就会RF。解决这个问题后就出现了PE,发现原来还有空字符串这种情况(题目中根本找不到半点提醒啊),结果是空字符串输入时还要输出个空行……

Run Time: 0sec                                                                        

Run Memory: 312KB

Code length: 765Bytes

SubmitTime: 2012-02-01 23:03:24

// Problem#: 1639
// Submission#: 1204089
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s, r;
    int n, count;

    while ( getline( cin, s ) ) {
        count = 0;
        r.clear();
        for ( int i = 0; i < s.size() && count <= 50; i++ ) {
            if ( s[ i ] >= '0' && s[ i ] <= '9' ) {
                n = 0;
                do {
                    n = n * 10 + ( s[ i ] - '0' );
                    i++;
                } while ( n <= 50 && s[ 0 ] >= '1' && s[ i ] <= '9' );
                r = r + string( n, s[ i ] );
                count += n;
            }
            else {
                r = r + s[ i ];
                count++;
            }
        }
        count <= 50 ? cout << r << endl: cout << "TOO LONG" << endl;
    }

    return 0;

}                                 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值