滴滴的第一题本地用例都通过,而且试了多组,但是提交就是0%
#include <iostream> #include <string> #include <stdlib.h> #include <algorithm> #include <math.h> using namespace std; std::string chengfa(std::string s1, std::string s2) { std::string sss(s1.size(), '0'); int temp, temp2, temp3; for (int kk = 0; kk < s2.size(); kk++) { std::string ss; ss.push_back((s2[s2.size() - 1 - kk] - '0') * (s1[s1.size() - 1] - '0') % 10 + '0'); temp2 = (s2[s2.size() - 1 - kk] - '0') * (s1[s1.size() - 1] - '0') / 10; for (int i = 1, j = 1; i < s1.size(); i++, j++) { ss.push_back(((s2[s2.size() - 1 - kk] - '0')* (s1[s1.size() - i - 1] - '0') + temp2) % 10 + '0');// + ((s2[s2.size() - 1 - kk] - '0') * (s1[s1.size() - i] - '0')) / 10 temp2 = ((s2[s2.size() - 1 - kk] - '0')* (s1[s1.size() - i - 1] - '0') + temp2) / 10;// + ((s2[s2.size() - 1 - kk] - '0') * (s1[s1.size() - i] - '0')) / 10 } ss.push_back(temp2 + '0'); //std::cout << temp2 << std::endl; std::reverse(ss.begin(), ss.end()); for (int mm = 0; mm < kk; mm++) ss.push_back('0'); //std::cout << ss<<std::endl; temp3 = sss[sss.size() - 1] - '0'; sss[sss.size() - 1] = (temp3 + (ss[ss.size() - 1] - '0')) % 10 + '0'; temp = (temp3 + (ss[ss.size() - 1] - '0')) / 10; //std::cout << temp << std::endl; for (int jjk = 1; jjk < sss.size(); jjk++) { temp3 = sss[sss.size() - jjk - 1] - '0'; sss[sss.size() - jjk - 1] = (temp3 + ss[ss.size() - jjk - 1] - '0' + temp) % 10 + '0'; temp = (temp3 + ss[ss.size() - jjk - 1] - '0' + temp) / 10; // std::cout << temp << std::endl; //temp = ( sss[sss.size() - jjk-1] - '0' + ss[ss.size() - jjk-1] - '0') / 10; } sss.insert(sss.begin(), ss[0] - '0' + temp + '0'); //std::cout << sss << std::endl; } if (sss[0] == '0') { std::string str2 = sss.substr(1, sss.size() - 1); return(str2); } else return(sss);; } int main() { std::string s1; int s2; int k=0; while (std::cin >> s1>>s2) { std::string temp; for (int i = 0; i < s1.size(); i++) { if (s1[i] == '.') k = s1.size() - i-1; else temp.push_back(s1[i]); } std::string result = "1"; for (int i = 1; i <= s2; i++) result = chengfa(result, temp); if (k!=0) result.insert(result.size()-k*s2, "."); std::cout << result<< std::endl; //std::cout << std::to_string(i); } system("pause"); }
先用C++写了个大数乘法的子函数,然后写的主函数,看着是麻烦了点,但是应该没问题,本地用例完全没有问题,但是提交就是0%,导致第二题都没做。