#7470: WA


yarke (Hi)

學校 : 不指定學校
編號 : 30894
來源 : [203.160.152.158]
最後登入時間 :
2015-11-09 17:20:23
a538. 11879 - Multiple of 17 -- UVa11879 | From: [123.110.73.215] | 發表日期 : 2013-02-04 23:56

#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;
}

想請問各位高手,有什麼情況是我未考慮到的嗎,請給我指教

 
#7474: Re:WA


yarke (Hi)

學校 : 不指定學校
編號 : 30894
來源 : [203.160.152.158]
最後登入時間 :
2015-11-09 17:20:23
a538. 11879 - Multiple of 17 -- UVa11879 | From: [219.87.175.130] | 發表日期 : 2013-02-05 13:36

#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;
}

想請問各位高手,有什麼情況是我未考慮到的嗎,請給我指教

總算找到問題了 ^^

 
ZeroJudge Forum