#2161: 8不能用

Unknown User

d085. 根號運算 -- 弱者 | From: [140.126.196.13] | 發表日期 : 2009-07-15 15:32

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,i,c;
while(cin>>a)
{
if (a>=0)
{
         b=int(sqrt(a));
         if(a==b*b)
         {cout<<b<<endl;}
         else
         {                                                  //else
             c=a;
         x:for(i=2;i<b;i++)                                 //x
             {                                              //for
                             if(a%(i*i)==0)
                             {                              //if
                                           a=a/(i*i);
                                           goto x;          //goto
                                           }                //if
                             }                              //for
c=c/a;
if (c==1)
{cout<<"_/"<<a<<endl;}
else {cout<<sqrt(c)<<"_/"<<a<<endl;}
             }                                              //else
        
         }
else if(a<0)
{
     a=abs(a);
     b=sqrt(a);
     if(a==b*b)
         {cout<<b<<"i"<<endl;}
              else
         {                                                  //else
             c=a;
         y:for(i=2;i<b;i++)                                 //y
             {                                              //for
                             if(a%(i*i)==0)
                             {                              //if
                                           a=a/(i*i);
                                           goto y;          //goto
                                           }                //if
                             }                              //for
c=c/a;
if (c==1)
{cout<<"_/"<<a<<"i"<<endl;}
else{cout<<sqrt(c)<<"_/"<<a<<"i"<<endl;}
             }                                              //else
    
    
     }
}
    system("pause");
    return 0;
    }

輸入8  或-8

輸出_/8  或_/8i

不是2_/2  或2_/2i

為什麼???救我...

 
#2181: Re:8不能用


david942j (文旋)

學校 : 臺北市立成功高級中學
編號 : 6086
來源 : [115.43.75.16]
最後登入時間 :
2017-02-18 13:17:39
d085. 根號運算 -- 弱者 | From: [58.115.138.158] | 發表日期 : 2009-07-21 13:39

#include
#include
using namespace std;
int main()
{
int a,b,i,c;
while(cin>>a)
{
if (a>=0)
{
         b=int(sqrt(a));
         if(a==b*b)
         {cout<         else
         {                                                  //else
             c=a;
         x:for(i=2;i             {                                              //for
                             if(a%(i*i)==0)
                             {                              //if
                                           a=a/(i*i);
                                           goto x;          //goto
                                           }                //if
                             }                              //for
c=c/a;
if (c==1)
{cout<<"_/"<else {cout<             }                                              //else
        
         }
else if(a<0)
{
     a=abs(a);
     b=sqrt(a);
     if(a==b*b)
         {cout<              else
         {                                                  //else
             c=a;
         y:for(i=2;i             {                                              //for
                             if(a%(i*i)==0)
                             {                              //if
                                           a=a/(i*i);
                                           goto y;          //goto
                                           }                //if
                             }                              //for
c=c/a;
if (c==1)
{cout<<"_/"<else{cout<             }                                              //else
    
    
     }
}
    system("pause");
    return 0;
    }

輸入8  或-8

輸出_/8  或_/8i

不是2_/2  或2_/2i

為什麼???救我...

輸入8時

b會等於2

這樣你的回圈會有問題

for(i=2;i<b;i++)                                

這不會跑

 
ZeroJudge Forum