#2392:


kai7537 (kai)

學校 : 不指定學校
編號 : 7567
來源 : [220.141.195.60]
最後登入時間 :
2011-10-16 17:22:52
d142. 10023 - Square root -- UVa10023 | From: [140.117.168.57] | 發表日期 : 2009-09-18 23:49

我的程式在給的測試資料上都是過的只是在line:6上答案是錯誤的

與正確輸出不相符(line:6)
您的答案為: 121
正確答案為: 10

合理的推測這個測試資料應該為100 

 但是我的程式在100時也是可以過

 

不知道是否有人能幫忙看一下

 #include <iostream>
#include <string>

using namespace std;
int convert_to_int(const char);
int test_1(int );
int test_2(int ,int );

int main()
{
    int n,a,b,divide,dividen,quot,length;
    string str;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        while(cin >> str)
        {
            length=str.length();
            if(length%2==0)
            {
                a=convert_to_int(str[0]);
                b=convert_to_int(str[1]);
                dividen=a*10+b;
                quot=divide=test_1(dividen);
                cout << quot;
                dividen=(dividen-quot*quot)*100;
                divide=divide*20;
                for(int j=2;j<length;j=j+2)
                {

                    a=convert_to_int(str[j]);
                    b=convert_to_int(str[j+1]);
                    dividen=dividen+a*10+b;
                    quot=test_2(divide,dividen);
                    cout << quot;
                    divide=divide+quot;
                    dividen=dividen-divide*quot;
                    divide=(divide+quot)*10;
                    dividen=dividen*100;
                    }
                cout << endl;break;
                }
            else
            {
                a=convert_to_int(str[0]);
                dividen=a;
                quot=divide=test_1(dividen);
                cout << quot;
                dividen=(dividen-quot*quot)*100;
                divide=divide*20;
                for(int j=1;j<length;j=j+2)
                {

                    a=convert_to_int(str[j]);
                    b=convert_to_int(str[j+1]);
                    dividen=dividen+a*10+b;
                    quot=test_2(divide,dividen);
                    cout << quot;
                    divide=divide+quot;
                    dividen=dividen-divide*quot;
                    divide=(divide+quot)*10;
                    dividen=dividen*100;
                    }
                cout << endl;break;
                }
                }
            }


    return 0;
}

int convert_to_int(const char c)
{
if( c == '0' ) return 0;
else if( c == '1' ) return 1;
else if( c == '2' ) return 2;
else if( c == '3' ) return 3;
else if( c == '4' ) return 4;
else if( c == '5' ) return 5;
else if( c == '6' ) return 6;
else if( c == '7' ) return 7;
else if( c == '8' ) return 8;
else if( c == '9' ) return 9;
else return -1 ;
}
int test_1(int k)
{
    for(int i=9;i>0;i--)
    {
        if(k>=i*i)
            return i;
        }
    }
int test_2(int d1,int d2)
{
    for(int i=9;i>0;i--)
    {
        if((d1+i)*i<=d2)
            return i;
        }
    }

 

謝謝!

 
ZeroJudge Forum