相信无论是谁看了都觉得是水题的一道题,但事实上我生生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;
}