Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
ACCEPTED的人请救我!前辈们的测试数据都能通过,但是就是Wrong Answer,实在找不到BUG在哪里。 首先具有一般性特征的数据能测试通过,说明算法的主体部分应该没错,极有可能是一些特例不能通过;其次根据前辈们的数据来看,特例也比较充分,但是也能通过。综合以后两点,对于Wrong Answer,我就是极其不爽。还望ACCEPTED的人给点建议。 贴上我的代码: #include <iostream> #include <string> using namespace std; bool stringMultiply(const string &str1, const string &str2, string &str3) { string *strArr = new string[str2.size()]; int i, j; for (j = str2.size() - 1; j >= 0; j--) { int tens = 0; for (i = str1.size() - 1; i >= 0; i--) { int product = (str2[j] - '0') * (str1[i] - '0') + tens; tens = product / 10; char units = product % 10 + '0'; strArr[j].append(1, units); if (i == 0 && tens != 0) { units = tens + '0'; strArr[j].append(1, units); } } } int tens = 0; for (j = 0; j < (int)(strArr[0].size() + str2.size() - 1); j++) { char units; int sum = 0; int strArrIdx = str2.size() - 1; for (i = 0; i < (int)str2.size(); i++) { if (j >= i && j < (int)strArr[strArrIdx].size() + i) { sum += (strArr[strArrIdx][j - i] - '0'); } --strArrIdx; } sum += tens; tens = sum / 10; units = sum % 10 + '0'; str3.append(1, units); if (j == (strArr[0].size() + str2.size() - 1) && tens != 0) { units = tens + '0'; str3.append(1, units); } } delete[] strArr; return true; } int main(int argc, char* argv[]) { string s; int n; //double r; while(cin>>s>>n) { //sscanf(s.c_str(), "%lg", &r); //if (n == 0) { // cout<<"1"<<endl; // continue; //} else if (r == 0) { // cout<<"0"<<endl; // continue; //} int n1 = n; int decimalPos = -1; int i = 0; for (i = 0; i < (int)s.size(); i++) { if (s[i] == '.') { decimalPos = i; break; } } if (decimalPos != -1) { s.erase(decimalPos, 1); } else { decimalPos = s.size(); } string result; string intermediateResult = s; string tempResult; string odd("1"); while (n > 1) { tempResult.clear(); stringMultiply(intermediateResult, s, tempResult); intermediateResult = tempResult; tempResult.clear(); stringMultiply(intermediateResult, odd, tempResult); intermediateResult = tempResult; --n; } result.clear(); stringMultiply(intermediateResult, odd, result); int insertIdx = (s.size() - decimalPos) * n1; if ((int)result.size() <= insertIdx) { result.insert(result.size(), insertIdx - result.size(), '0'); result.append(1, '.'); } else { result.insert(insertIdx, 1, '.'); } string copyResult = result; result.clear(); int i1,i2; for (i = copyResult.size() - 1; i >= 0; i--) { if (copyResult[i] != '0') { i2 = i; break; } } for (i = 0; i < (int)copyResult.size(); i++) { if (copyResult[i] != '0') { i1 = i; break; } } for (i = i2; i >= i1; i--) { result.append(1, copyResult[i]); } if (result[result.size() - 1] == '.') { result.erase(result.size() - 1, 1); } cout<<result<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator