#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
using namespace std;
int strTransferToint(string strNum)
{
int nVal;
stringstream strToint;
strToint.clear();
strToint.str(strNum);
strToint >> dec >> nVal;
return nVal;
}
void Check_Multiple_Of_17(string strInput)
{
string strLastNum , strLastTwoNum;
int nVal;
stringstream strToint;
string strTmpInput = "";
string strTmp = "";
if (strInput.size() < 10)
{
strToint.clear();
strToint.str(strInput);
strToint >> dec >> nVal;
/*
if (nVal % 17 == 0)
{
cout << "1" << endl;
}
else
{
cout << "0" << endl;
}
*/
printf("%d\n",(nVal % 17 == 0)?1:0);
strLastNum.erase();
strLastTwoNum.erase();
strTmpInput.erase();
strTmp.erase();
}
else
{
int nLastPos = strInput.size() - 1;
int nLastTwoPos = strInput.size() - 3;
int nLastNum , nLastTwoNum;
strLastNum.erase();
strLastTwoNum.erase();
strLastNum = strInput.substr (nLastPos , 1);
strLastTwoNum = strInput.substr (nLastTwoPos , 2);
nLastNum = strTransferToint(strLastNum);
nLastTwoNum = strTransferToint(strLastTwoNum);
int nZeroCount = 0;
int nCount = 2;
int nNum = nLastTwoNum - 5 * nLastNum;
while (nNum < 0)
{
++nZeroCount;
if (nZeroCount > 9)
{
break;
}
strLastTwoNum = strInput.substr (--nLastTwoPos , ++nCount);
nLastTwoNum = strTransferToint(strLastTwoNum);
nNum = nLastTwoNum - 5 * nLastNum;
}
if (nZeroCount > 9)
{
for (int nIdx = 0 ; nIdx < strInput.size() ; ++nIdx)
{
string str;
str = strInput.at(nIdx);
if (str == "0")
{
continue;
}
strTmpInput += str;
}
}
else
{
strTmpInput = strInput.substr (0 , nLastTwoPos);
}
strTmp.erase();
if (nNum > 0)
{
if (nNum < 10)
{
strTmp += "0";
}
stringstream intTostr(strTmp);
intTostr << nNum;
strTmp += intTostr.str();
strTmpInput += strTmp;
}
Check_Multiple_Of_17(strTmpInput);
}
}
int main()
{
string strInput;
while (cin >> strInput)
{
if (strInput == "0")
{
break;
}
//int Res = Check_Multiple_Of_17(strInput);
Check_Multiple_Of_17(strInput);
}
return 0;
}
想請問各位高手,有什麼情況是我未考慮到的嗎,請給我指教
#include
#include
#include
#include
using namespace std;
int strTransferToint(string strNum)
{
int nVal;
stringstream strToint;
strToint.clear();
strToint.str(strNum);
strToint >> dec >> nVal;
return nVal;
}
void Check_Multiple_Of_17(string strInput)
{
string strLastNum , strLastTwoNum;
int nVal;
stringstream strToint;
string strTmpInput = "";
string strTmp = "";
if (strInput.size() < 10)
{
strToint.clear();
strToint.str(strInput);
strToint >> dec >> nVal;
/*
if (nVal % 17 == 0)
{
cout << "1" << endl;
}
else
{
cout << "0" << endl;
}
*/
printf("%d\n",(nVal % 17 == 0)?1:0);
strLastNum.erase();
strLastTwoNum.erase();
strTmpInput.erase();
strTmp.erase();
}
else
{
int nLastPos = strInput.size() - 1;
int nLastTwoPos = strInput.size() - 3;
int nLastNum , nLastTwoNum;
strLastNum.erase();
strLastTwoNum.erase();
strLastNum = strInput.substr (nLastPos , 1);
strLastTwoNum = strInput.substr (nLastTwoPos , 2);
nLastNum = strTransferToint(strLastNum);
nLastTwoNum = strTransferToint(strLastTwoNum);
int nZeroCount = 0;
int nCount = 2;
int nNum = nLastTwoNum - 5 * nLastNum;
while (nNum < 0)
{
++nZeroCount;
if (nZeroCount > 9)
{
break;
}
strLastTwoNum = strInput.substr (--nLastTwoPos , ++nCount);
nLastTwoNum = strTransferToint(strLastTwoNum);
nNum = nLastTwoNum - 5 * nLastNum;
}
if (nZeroCount > 9)
{
for (int nIdx = 0 ; nIdx < strInput.size() ; ++nIdx)
{
string str;
str = strInput.at(nIdx);
if (str == "0")
{
continue;
}
strTmpInput += str;
}
}
else
{
strTmpInput = strInput.substr (0 , nLastTwoPos);
}
strTmp.erase();
if (nNum > 0)
{
if (nNum < 10)
{
strTmp += "0";
}
stringstream intTostr(strTmp);
intTostr << nNum;
strTmp += intTostr.str();
strTmpInput += strTmp;
}
Check_Multiple_Of_17(strTmpInput);
}
}
int main()
{
string strInput;
while (cin >> strInput)
{
if (strInput == "0")
{
break;
}
//int Res = Check_Multiple_Of_17(strInput);
Check_Multiple_Of_17(strInput);
}
return 0;
}
想請問各位高手,有什麼情況是我未考慮到的嗎,請給我指教