滴滴的第一题本地用例都通过,而且试了多组,但是提交就是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%,导致第二题都没做。

全部评论
第二题没做+1
点赞 回复 分享
发布于 2017-09-23 21:06

相关推荐

头像
11-09 17:30
门头沟学院 Java
TYUT太摆金星:我也是,好几个华为的社招找我了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务