#18992: 求救NA


Easonsfriend (去寫./Problems?ownerid=89827)

學校 : 不指定學校
編號 : 89827
來源 : [106.105.188.90]
最後登入時間 :
2024-04-23 23:15:35
b538. 分數運算-2 -- 分數四則 | From: [106.105.188.90] | 發表日期 : 2019-08-23 02:40

查看評分詳細結果。

#0: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 67/8

#1: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 290/51

#2: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 896/145

#3: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 131/21


___________________________________

#include <iostream>

#include <cmath>

using namespace std;

 

 

void compute(int n,int m){

    

        int max;

        if(abs(n)>abs(m)){

        for(int j=1;j<=n;j++){

            if(abs(n)%j==0&&abs(m)%j==0){

                max=j;

            }

            

        }

    }else{

        for(int j=1;j<=m;j++){

            if(abs(n)%j==0&&abs(m)%j==0){

                max=j;

            }

            

        }

        

    }

    if(n==0){

        cout<<"0\n";

    }

    else if(m/max==-1)cout<<-n/max<<"\n";

    else if(m/max==1)cout<<n/max<<"\n";

    else if(m<0)cout<<-n/max<<'/'<<-m/max<<"\n";

    else cout<<n/max<<'/'<<m/max<<"\n";

    

}

 

 

 

int main(){

    ios::sync_with_stdio(false) ;

    cin.tie(0);

    int a,b,c,d;

    char s;

    while(cin>>a>>b>>c>>d>>s){

        switch (s) {

            case'+' :{

                

                int n=a*d+b*c;

                int m=b*d;

                compute(n,m);

                break;

            }

            case'-':{

                

                int n=a*d-b*c;

                int m=b*d;

                compute(n,m);

                break;

            }

            case'*':{

                

                int n=a*c;

                int m=b*d;

                compute(n,m);

                break;

            }

                

            case'/':{

               

                int n=a*d;

                int m=b*c;

                compute(n,m);

                break;

            }

        }

    }

}

 
#18993: Re:求救NA


Easonsfriend (去寫./Problems?ownerid=89827)

學校 : 不指定學校
編號 : 89827
來源 : [106.105.188.90]
最後登入時間 :
2024-04-23 23:15:35
b538. 分數運算-2 -- 分數四則 | From: [106.105.188.90] | 發表日期 : 2019-08-23 02:42

查看評分詳細結果。

#0: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 67/8

#1: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 290/51

#2: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 896/145

#3: 25% WA (line:1)

您的答案為: 0/0
正確答案為: 131/21


___________________________________

#include

#include

using namespace std;

 

 

void compute(int n,int m){

    

        int max;

        if(abs(n)>abs(m)){

        for(int j=1;j<=n;j++){

            if(abs(n)%j==0&&abs(m)%j==0){

                max=j;

            }

            

        }

    }else{

        for(int j=1;j<=m;j++){

            if(abs(n)%j==0&&abs(m)%j==0){

                max=j;

            }

            

        }

        

    }

    if(n==0){

        cout<<"0\n";

    }

    else if(m/max==-1)cout<<-n/max<<"\n";

    else if(m/max==1)cout<<n/max<<"\n";

    else if(m<0)cout<<-n/max<<'/'<<-m/max<<"\n";

    else cout<<n/max<<'/'<<m/max<<"\n";

    

}

 

 

 

int main(){

    ios::sync_with_stdio(false) ;

    cin.tie(0);

    int a,b,c,d;

    char s;

    while(cin>>a>>b>>c>>d>>s){

        switch (s) {

            case'+' :{

                

                int n=a*d+b*c;

                int m=b*d;

                compute(n,m);

                break;

            }

            case'-':{

                

                int n=a*d-b*c;

                int m=b*d;

                compute(n,m);

                break;

            }

            case'*':{

                

                int n=a*c;

                int m=b*d;

                compute(n,m);

                break;

            }

                

            case'/':{

               

                int n=a*d;

                int m=b*c;

                compute(n,m);

                break;

            }

        }

    }

}

但自己測跟測試執行都是對的


 
ZeroJudge Forum