0
我通過做法學習,並享受使用在線評判網站學習。目前我正在致力於 http://www.z-training.net/tasks.php?show_task=5000000406。一些測試用例通過,但很多都得到MLE/SEGF。我的代碼採取暴力手段。這種方法是否是MLE/SEGF錯誤的原因?MLE/SEGF錯誤
//z-last char
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "";
string tmp = "";
string newStr = "";
unsigned int strSize = 0;
unsigned int repeat;
unsigned int i;
int cnt = 0;
cin >> str;
cin >> repeat;
tmp = str;
strSize = str.size();
for (i=1;i<repeat;i++)
{
str += tmp;
strSize += strSize;
}
while (strSize > 1)
{
cnt = 0;
newStr = "";
for (i=1;i<strSize;i=i+2)
{
newStr += str[i];
cnt += 1;
}
//cout << newStr << endl;
strSize = cnt;
str = newStr;
}
cout << newStr << endl;
return 0;
}
如果您向我們提供導致問題的一些輸入信息,將會有所幫助。 – 2011-02-15 17:31:20