80pts,求调

P1067 [NOIP2009 普及组] 多项式输出

Guanguplussss @ 2024-10-07 09:34:19

Subtask #0:#4,#11 WA

Subtask #1:#1 WA 代码:

#include<bits/stdc++.h>
using namespace std;
int n,a[110];
void print(int &x,int &d){
    if(x==0){
        return;
    }
    if(d==0){
        if(x>0){
            cout<<"+"<<x;
        }else{
            cout<<x;
        }
        return;
    }
    if(x==1){
        if(d==1){
            cout<<"+x";
        }else{
            cout<<"+x^"<<d;
        }
        return;
    }else if(x==-1){
        if(d==1){
            cout<<"-x";
        }else{
            cout<<"-x^"<<d;
        }
        return;
    }else{
        if(x>0){
            if(d==1){
                cout<<"+"<<x<<"x";
            }else{
                cout<<"+"<<x<<"x^"<<d;
            }
            return;
        }else{
            if(d==1){
                cout<<x<<"x";
            }else{
                cout<<x<<"x^"<<d;
            }
            return;
        }
    }
}
int main(){ 
    cin>>n;
    for(int i=n;i>=0;i--){
        cin>>a[i];
    }
    for(int i=n;i>=0;i--){
        if(i==n){
            if(a[n]==1){
                cout<<"x^"<<n;
            }else if(n==-1){
                cout<<"-x^"<<n;
            }else{
                cout<<a[n]<<"x^"<<n;
            }
        }else{
            print(a[i],i);
        }
    } 
    return 0;
}

代码:


by liyuhao188_7788 @ 2024-10-07 09:45:43

#include<bits/stdc++.h>
using namespace std;
int n;
int a;
int main()
{
    cin>>n;
    for(int i=n;i>=0;i--)
    {
        cin>>a;
        if(a!=0)
        {
            if(a>0 && i!=n) {
                cout<<'+';
            }
            if(abs(a)>1 || i==0){
                cout<<a;
            } 
            if(a==-1 && i) {
                cout<<'-';
            }
            if(i!=0 && i!=1){
                cout<<'x'<<'^'<<i;
            }
            if(i==1){
                cout<<'x';
            } 
        }
    }
 }

求关


by ldhuzihao @ 2024-10-10 13:59:53

@Guanguplussss

#include<bits/stdc++.h>
using namespace std;
int n,s;
int main(){
    cin>>n;
    for(int i=n;i>=0;i--){
        cin>>s;
        if(s){ 
            if(i!=n&&s>0)cout<<"+";
            if(abs(s)>1||i==0)cout<<s;  
            if(s==-1&&i)cout<<"-";  
            if(i>1)cout<<"x^"<<i;    
            if(i==1)cout<<"x";  
        }
    }
    return 0; 
}

满分代码求回关


by Guanguplussss @ 2024-10-13 07:36:24

@liyuhao188_7788

@ldhuzihao

栓Q!


by ldhuzihao @ 2024-10-13 12:32:57

@Guanguplussss

不客气


by Guanguplussss @ 2024-10-19 11:22:54

@liyuhao188_7788
@ldhuzihao
已互关


by ldhuzihao @ 2024-10-19 12:28:45

OK


by liyuhao188_7788 @ 2024-10-19 20:31:10

好的


by Guanguplussss @ 2024-10-23 19:25:29

PS:
已A


|