题解

27 条题解

  • 1
    @ 2021-08-30 09:57:13
    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int n,a; cin>>n;
        for(int i=n;i>=0;i--){
            cin>>a;
            if(a){
                if(i!=n&&a>0)
                    cout<<"+";
                if(abs(a)>1||i==0)
                    cout<<a;
                if(a==-1&&i)
                    cout<<"-";
                if(i>1)
                    cout<<"x^"<<i;
                if(i==1)
                    cout<<"x";
            }
        }
        return 0;
    }
    
  • 1
    @ 2018-02-06 10:13:14
    #include<bits/stdc++.h>
    long long int n, m;
    long long int num[110];
    int main() {
        scanf("%lld", &n);
        for(int i=1; i<=n+1; i++)
            scanf("%lld", &num[i]);
        if(fabs(num[1])!=1) printf("%lldx^%lld", num[1], n);
        else {
            if(num[1]==1) printf("x^%lld", n);
            else printf("-x^%lld", n);
        }
        int j=n;
        for(int i=2; i<n; i++) {
            j--;
            if(num[i]==0) continue;
            else {
                if(fabs(num[i])==1) {
                    if(num[i]==1) printf("+x^%lld", j);
                    if(num[i]==-1) printf("-x^%lld", j);
                } else {
                    if(num[i]>0) printf("+%lldx^%lld", num[i], j);
                    if(num[i]<0) printf("%lldx^%lld", num[i], j);
                }
            }
        }
        if(num[n]!=0) {
            if(num[n]>0) {
                if(num[n]==1) printf("+x");
                if(num[n]!=1) printf("+%lldx", num[n]);
            }
            if(num[n]<0) {
                if(num[n]==-1) printf("-x");
                if(num[n]!=-1) printf("%lldx", num[n]);
            }
        }
        if(num[n+1]==0) printf("\n");
        else {
            if(num[n+1]>0) printf("+%lld", num[n+1]);
            if(num[n+1]<0) printf("%lld", num[n+1]);
        }
        return 0;
    }
    
  • 0
    @ 2018-04-22 22:42:44
    #include <iostream>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int n2=n;
        if(n==1)
        {
            int m,n1;
            cin>>m>>n1;
            if(m!=0)
            {
                if(m==1)
                {
                    if(n1>0) cout<<"x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<"x"<<endl;
                    else if(n1<0) cout<<"x"<<n1<<endl;
                }
                else if(m==-1)
                {
                    if(n1>0) cout<<"-x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<"-x"<<endl;
                    else if(n1<0) cout<<"-x"<<n1<<endl;
                } 
                else 
                {
                    if(n1>0) cout<<m<<"x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<m<<"x"<<endl;
                    else if(n1<0) cout<<m<<"x"<<n1<<endl;
                }
            }
            else if(m==0)
            {
                cout<<n1<<endl;
            }
        }
        else if(n>1)
        {
            int a[101];
            int i,j,n1,m;
            for(i=1;i<=n+1;i++)
                cin>>a[i];
            m=a[n];n1=a[n+1];
            bool flag=false;
            for(i=1;i<=n2-1;i++)
            {
                if(a[i]!=0)
                {
                    flag=true;
                    if(a[i]!=1&&a[i]!=-1) cout<<a[i]<<"x^"<<n;
                    else if(a[i]==1) cout<<"x^"<<n;
                    else if(a[i]==-1) cout<<"-x^"<<n;
                    n--;
                    if(a[i+1]>0) cout<<"+";
                }
                else if(a[i]==0)
                {
                    n--;
                    if(a[i+1]>0&&flag==true) cout<<"+";
                }
            }
            if(flag==true)
            {
                if(m!=0)
                {
                    if(m==1)
                    {
                        if(n1>0) cout<<"x"<<"+"<<n1<<endl;
                        else if(n1==0) cout<<"x"<<endl;
                        else if(n1<0) cout<<"x"<<n1<<endl;
                    }
                    else if(m==-1)
                    {
                        if(n1>0) cout<<"-x"<<"+"<<n1<<endl;
                        else if(n1==0) cout<<"-x"<<endl;
                        else if(n1<0) cout<<"-x"<<n1<<endl;
                    } 
                    else if(m>0&&m!=-1)
                    {
                        //cout<<"+";
                        if(n1>0) cout<<m<<"x"<<"+"<<n1<<endl;
                        else if(n1==0) cout<<m<<"x"<<endl;
                        else if(n1<0) cout<<m<<"x"<<n1<<endl;
                    }
                    else if(m<0&&m!=-1)
                    {
                        if(n1>0) cout<<m<<"x"<<"+"<<n1<<endl;
                        else if(n1==0) cout<<m<<"x"<<endl;
                        else if(n1<0) cout<<m<<"x"<<n1<<endl;
                    }
                }
                else if(m==0)
                {
                    if(n1<0) cout<<n1<<endl;
                    else if(n1>0) cout<<"+"<<n1;
                }   
            }
            else if(flag==false)
            {
                if(m!=0)
            {
                if(m==1)
                {
                    if(n1>0) cout<<"x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<"x"<<endl;
                    else if(n1<0) cout<<"x"<<n1<<endl;
                }
                else if(m==-1)
                {
                    if(n1>0) cout<<"-x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<"-x"<<endl;
                    else if(n1<0) cout<<"-x"<<n1<<endl;
                } 
                else 
                {
                    if(n1>0) cout<<m<<"x"<<"+"<<n1<<endl;
                    else if(n1==0) cout<<m<<"x"<<endl;
                    else if(n1<0) cout<<m<<"x"<<n1<<endl;
                }
            }
            else if(m==0)
            {
                cout<<n1<<endl;
            }
            }
        }
        return 0;
    }
    
  • 0
    @ 2017-11-10 20:02:36

    //注意细节!!!!!!
    var n,i:longint;
    a:array[0..102]of longint;
    p:shortstring;
    begin
    readln(n);
    for i:=n downto 0 do read(a[i]);
    for i:=n downto 1 do
    begin
    if a[i]=0 then continue;
    p:='';
    if a[i]>0 then p:='+'
    else p:='-';
    if(i=n)and(a[i]>0)then p:='';
    a[i]:=abs(a[i]);
    if a[i]=1 then write(p,'x^',i)
    else write(p,a[i],'x^',i);
    end;
    if a[0]<>0 then
    begin
    p:='';
    if a[0]>0 then p:='+'
    else p:='-';
    a[0]:=abs(a[0]);
    if a[0]=1 then writeln(p,'x')
    else writeln(p,a[0])
    end;
    end.

  • 0
    @ 2017-10-22 11:16:49

    #include<stdio.h>
    int a[105];
    int main()
    {
    freopen("poly.in","r",stdin);
    freopen("poly.out","w",stdout);
    int n,i,j;
    scanf("%d",&n);
    for(i=n;i>=0;i--)//输入系数
    scanf("%d",&a[i]);
    //下面3个if语句处理最高次项(首项)的情况
    if(a[n]>0&&a[n]!=1||a[n]<0&&a[n]!=-1)
    printf("%dx^%d",a[n],n);
    if(a[n]==1)printf("x^%d",n);
    if(a[n]==-1)printf("-x^%d",n);
    for(i=n-1;i>=2;i--)
    { //下面4个if语句处理中间项(非一次项)的情况
    if(a[i]>0&&a[i]!=1)printf("+%dx^%d",a[i],i);
    if(a[i]<0&&a[i]!=-1)printf("%dx^%d",a[i],i);
    if(a[i]==1)printf("+x^%d",i);
    if(a[i]==-1)printf("-x^%d",i);
    }
    //下面4个if语句处理一次项的情况
    if(a[1]>0&&a[1]!=1)printf("+%dx",a[1]);
    if(a[1]<0&&a[1]!=-1)printf("%dx",a[1]);
    if(a[1]==1)printf("+x");
    if(a[1]==-1)printf("-x");
    //下面2个if语句处理常数项的情况
    if(a[0]>0)printf("+%d",a[0]);
    if(a[0]<0)printf("%d",a[0]);
    return 0;
    }

    • @ 2017-10-22 11:37:15

      注意去掉freopen

  • 0
    @ 2017-10-21 10:32:06

    pascal

    var
    n:longint;
    a:array[1..500]of longint;
    i,j,s:longint;
    begin
    readln(n);
    for i:=1 to n+1 do
    read(a[i]);
    for s:=1 to n+1 do
    if a[s]<>0 then
    begin
    if s=n+1 then write(a[s])//只有一个
    else
    begin
    if a[s]<0 then write('-');
    a[s]:=abs(a[s]);
    if a[s]<>1 then write(a[s]);
    if s=n then write('x')
    else write('x^',n+1-s);
    end;
    break;
    end;//处理第一个

    for i:=s+1 to n+1 do
    if a[i]<>0 then
    begin
    if a[i]>0 then write('+')
    else write('-');
    if (abs(a[i])<>1)or(i=n+1) then write(abs(a[i]));//常数为一或系数不为一
    if i<>n+1 then
    if i=n then write('x')
    else write('x^',n+1-i);

    end;
    end.

  • 0
    @ 2017-08-12 14:31:13

    #include<iostream>
    int n[101];
    using namespace std;
    int main()
    {
    int a,i,k=0,m=0;
    cin>>a;
    for(i=1;i<=a+1;i++)
    {
    cin>>n[i];
    }
    for(i=1;i<=a+1;i++)
    {
    if(n[i]!=0)
    {
    m++;
    }
    }
    if(m==0)
    {
    cout<<"0";
    return 0;
    }
    if(a==0)
    {
    cout<<n[1];
    return 0;
    }
    for(i=a;i>0;i--)
    {
    if(k==0&&n[a-i+1]!=0)
    {
    if(n[a-i+1]!=1&&n[a-i+1]!=-1)
    {
    cout<<n[a-i+1];
    }
    if(n[a-i+1]==-1)
    {
    cout<<"-";
    }
    cout<<"x^"<<i;
    k++;
    continue;
    }
    if(k==1)
    {
    if(n[a-i+1]==0)
    {
    continue;
    }
    else
    {
    if(n[a-i+1]>0)
    {
    cout<<"+";
    }
    if(n[a-i+1]!=1&&n[a-i+1]!=-1)
    {
    cout<<n[a-i+1];
    }
    else if(n[a-i+1]==-1)
    {
    cout<<"-";
    }
    if(i==1)
    cout<<"x";
    else
    cout<<"x^"<<i;
    }
    }
    }
    if(n[a+1]==0)
    {
    return 0;
    }
    else if(n[a+1]>0)
    {
    cout<<"+";
    }
    cout<<n[a+1];
    }

  • 0
    @ 2017-08-12 14:30:57

    #include<iostream>
    int n[101];
    using namespace std;
    int main()
    {
    int a,i,k=0,m=0;
    cin>>a;
    for(i=1;i<=a+1;i++)
    {
    cin>>n[i];
    }
    for(i=1;i<=a+1;i++)
    {
    if(n[i]!=0)
    {
    m++;
    }
    }
    if(m==0)
    {
    cout<<"0";
    return 0;
    }
    if(a==0)
    {
    cout<<n[1];
    return 0;
    }
    for(i=a;i>0;i--)
    {
    if(k==0&&n[a-i+1]!=0)
    {
    if(n[a-i+1]!=1&&n[a-i+1]!=-1)
    {
    cout<<n[a-i+1];
    }
    if(n[a-i+1]==-1)
    {
    cout<<"-";
    }
    cout<<"x^"<<i;
    k++;
    continue;
    }
    if(k==1)
    {
    if(n[a-i+1]==0)
    {
    continue;
    }
    *else*
    {
    if(n[a-i+1]>0)
    {
    cout<<"+";
    }
    if(n[a-i+1]!=1&&n[a-i+1]!=-1)
    {
    cout<<n[a-i+1];
    }
    else if(n[a-i+1]==-1)
    {
    cout<<"-";
    }
    if(i==1)
    cout<<"x";
    else
    cout<<"x^"<<i;
    }
    }
    }
    if(n[a+1]==0)
    {
    return 0;
    }
    else if(n[a+1]>0)
    {
    cout<<"+";
    }
    cout<<n[a+1];
    }

  • 0
    @ 2017-08-03 10:22:33
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    
    int n;
    int xs[105];
    
    int main() {
        cin >> n;
        for (int i = n; i >= 0; i--) cin >> xs[i];
        if (xs[n] > 0) {
            if (xs[n] != 1)cout << xs[n] << "x^" << n;
            else cout << "x^" << n;
            n--;
        }
        
        while (n != -1) {
            if (xs[n] == 0) {
                n--;
                continue;
            }
            if (xs[n] > 0) cout << '+';
            if (n != 0 && n != 1) {
                if (xs[n] != 1 && xs[n] != -1) cout << xs[n];
                if (xs[n] == -1) cout << '-';
                cout << "x^" << n;
            }
            else if (n == 0) { 
                cout << xs[n]; 
            }
            else if (n == 1) { 
                if (xs[n] != 1 && xs[n] != -1)cout << xs[n]; 
                if (xs[n] == -1) cout << '-';
                cout << "x";
            }
            n--;
        }   
        return 0;
    }
    
  • 0
    @ 2016-11-06 11:43:27

    为什么我那么短==我明明AC了呀==
    ~~~c++
    测试数据 #0: Accepted, time = 0 ms, mem = 564 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 564 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    Accepted, time = 0 ms, mem = 568 KiB, score = 100

    #include<bits/stdc++>
    using namespace std;
    int n,i,t;
    int main(){
    cin>>n;
    for(i=n;i>=0;i--){
    cin>>t;
    if(t==0) continue;
    if(t<0){
    cout<<'-';t=-t;
    }
    else if(i!=n) cout<<'+';
    if(i==0){
    cout<<t;return 0;
    }
    if(t!=1) cout<<t;
    if(i>0) cout<<'x';
    if(i>1) cout<<'^'<<i;
    }
    }
    ~~~

  • 0
    @ 2016-09-06 12:19:47
    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    Accepted, time = 0 ms, mem = 560 KiB, score = 100
    代码
    #include <iostream>
    using namespace std;
    int main() {
      ios :: sync_with_stdio(false);
      //ifstream cin("poly.in",ios :: in);
      //ofstream cout("poly.out",ios :: out);
      int n,x;
      cin >> n >> x;
      if (x == 1) cout << "x^" << n;
      else if (x == -1) cout << "-x^" << n;
      else cout << x << "x^" << n;
      for (int i = 1;i < n-1;i++) {
        cin >> x;
        if (x == 1) cout << "+x^" << n-i;
        else if (x == -1) cout << "-x^" << n-i;
        else if (x > 0) cout  << '+' << x << "x^" << n-i;
        else if (x < 0) cout  << x << "x^" << n-i;
      }
      cin >> x;
      if (x == 1) cout << "+x";
      else if (x == -1) cout << "-x";
      else if (x > 0) cout << '+' << x << "x";
      else if (x > 0) cout << '+' << x << "x";
      else if (x < 0) cout << x << "x";
      cin >> x;
      if (x > 0) cout << '+' << x;
      else if (x < 0) cout << x;
      return 0;
    }
    
  • 0
    @ 2016-03-17 19:03:29

    细节题。所有细节都考虑到了的话自然就AC了。
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <algorithm>
    int abs(int x) {
    if (x>0)
    return x;
    return -x;

    }
    using namespace std;
    int a[107],n;
    int main() {
    scanf("%d",&n);
    for (int i=n;i>-1;i--)
    scanf("%d",a+i);
    bool flag=0;
    for (int i=n;i>-1;i--) {
    if (a[i]==0)
    continue;
    if (flag) {
    if (a[i]>0)
    printf("+");
    }
    if (a[i]<0)
    printf("-");
    if ((abs(a[i]))>1)
    printf("%d",abs(a[i]));
    if (i!=0) {
    printf("x");
    if (i>1)
    printf("^%d",i);
    }
    flag=1;
    }
    if (abs(a[0])==1)
    printf("1");
    return 0;
    }

    • @ 2016-08-15 10:26:28

      <cmath>里就有abs(n)啊......

  • 0
    @ 2016-03-17 07:43:12

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,a[100];
    int main()
    {
    freopen("p.in","r",stdin);
    freopen("p.out","w",stdout);
    cin>>n;
    for(int i=0;i<=n;i++)
    cin>>a[i];
    if(n==1) cout<<a[0]<<"x";
    else
    {
    if(abs(a[0])==1)
    {
    if(a[0]==1)
    cout<<"x^"<<n;
    if(a[0]==-1)
    cout<<"-x^"<<n;
    }
    else
    cout<<a[0]<<"x^"<<n;
    }
    for(int i=1;i<=n-2;i++)
    {
    if(a[i]>0) cout<<"+";
    if(a[i]==0) continue;
    if(abs(a[i])==1)
    {
    if(a[i]==1) cout<<"x^"<<n-i;
    if(a[i]==-1) cout<<"-x^"<<n-i;
    }
    else
    {
    cout<<a[i]<<"x^"<<n-i;
    }

    }

    if(n>2)
    {
    if(a[n-1]==1) cout<<"+x";
    if(a[n-1]!=1 && a[n-1]>0) cout<<"+"<<a[n-1]<<"x";
    if(a[n-1]<0) cout<<a[n-1]<<"x";
    }

    if(a[n]>0) cout<<"+"<<a[n];

    if(a[n]<0) cout<<a[n];
    return 0;

    }

    题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题题题题题水水水水题题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题水水水水水水水水水题题题题
    题题题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题
    题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题题题
    题题题题题题题题题题题水水水水题水水水水水水水水水水水题题题题题题题题题题
    题题题题题题题题水水水水水水水题水水水题题水水水水水题题题题题题题题题题题
    题题题水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
    题水水水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
    题水水水水水水水水水水水水题题题题题题题水水水水水水水水水水水题题题题题题
    题水水水水水水水水水水水水题题题题题题水水水水水水水水水水水水水水题题题题
    题题水水水水水水水水水水题题题题题水水水水水水题题题水水水水水水水题题题题
    题题题题题题题题水水水水题题题题题水水水水题题题题题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水题题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水题题水水水水题题水水水水水题题题题题
    题题水水题题题水水水水水题题题题水水水题题水水水题题题水水水水水题题题题题
    题题水水水水水水水水水水题题题题题水水题题水水题题题题水水水水水题题题题题
    题题题水水水水水水水水水题题题题题题题题水水水题题题题水水水水题题题题题题
    题题题题题水水水水水水水题题题题题题题题水水水题水水水水题题题题题题题题题
    题题题题题题水水水水水水题题题题题题题水水水水题题水水水水题题题题题题题题
    题题题题题题题题题水水水题题题题题题水水水水水题题题水水水水水水水题题题题
    题题题题题题题题题题题题题题题题水水水水水水题题题题题水水水水水水题题题题
    题题题题题题题题题题题题题题题水水水水水水题题题题题题水水水水水水水题题题
    题题题题题题题题题题题题题题水水水水水题题题题题题题题题水水水水水水题题题
    题题题题题题题题题题题题题水水水水水题题题题题题题题题题题水水水水题题题题
    题题题题题题题题题题题题水水水题题题题题题题题题题题题题题题水水水题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题

  • 0
    @ 2016-03-16 16:28:40

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,a[100],i;
    int main()
    {
    freopen("p.in","r",stdin);
    freopen("p.out","w",stdout);
    cin>>n;
    for(i=0;i<=n;i++) cin>>a[i]; //读入数据

    for(i=0;i<=n;i++) //从第一个到最后一个
    {

    if(i==0)
    {
    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(abs(a[i])==1)
    {
    if(a[i]==1)
    {
    cout<<a[i]<<"x^"<<n;
    }
    if(a[i]==-1)
    {
    cout<<a[i]<<"x^"<<n;
    }
    }
    else
    {
    if(a[i]>0)
    {
    cout<<a[i]<<"x^"<<n;
    }
    if(a[i]<0)
    {
    cout<<a[i]<<"x^"<<n;
    }
    }
    }
    }

    //以上是处理第一项,证明已成功了。

    //以下处理第2项到最后第2项的程序,请参观
    if (i>0&&i<n)
    {

    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(abs(a[i])==1)
    {
    if(a[i]==1)
    {
    cout<<"+"<<"x^"<<n-i;
    }
    else
    {
    cout<<"x^"<<n-i;
    }
    }
    else
    {
    if(a[i]>0)
    {
    cout<<"+"<<a[i]<<"x^"<<n-i;
    }
    else
    {
    cout<<a[i]<<"x^"<<n-i;
    }
    }
    }
    }

    //以下是处理最后一个
    if(i==n)
    {
    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(a[i]>0)
    {
    cout<<"+"<<a[i];
    }
    if(a[i]<0)
    {
    cout<<a[i];
    }
    }
    }

    }

    return 0;
    }

    • @ 2016-05-23 12:53:54

      你够了。苏苏啊,这样连发两个题解真的好吗。。。

    • @ 2017-10-21 10:29:43

      嗯,和我的代码很像,不过我是pascal...

  • 0
    @ 2016-03-16 10:28:24

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,a[100],i;
    int main()
    {
    cin>>n;
    for(int i=0;i<=n;i++)
    {
    cin>>a[i];
    if(i==0)
    {
    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(abs(a[i])==1)
    {
    if(a[i]==1)
    {
    cout<<a[i]<<"x^"<<n;
    }
    if(a[i]==-1)
    {
    cout<<"-"<<a[i]<<"x^"<<n;
    }
    }
    else
    {
    if(a[i]>0)
    {
    cout<<a[i]<<"x^"<<n;
    }
    if(a[i]<0)
    {
    cout<<"-"<<a[i]<<"x^"<<n;
    }
    }
    }
    }

    for(int i=1;i<n;i++)
    {
    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(abs(a[i])==1)
    {
    if(a[i]==1)
    {
    cout<<"+"<<"x^"<<n-i;
    }
    if(a[i]==-1)
    {
    cout<<"-"<<"x^"<<n-i;
    }
    }
    else
    {
    if(a[i]>0)
    {
    cout<<"+"<<a[i]<<"x^"<<n-i;
    }
    if(a[i]<0)
    {
    cout<<"-"<<a[i]<<"x^"<<n-i;
    }
    }
    }

    }
    if(i==n)
    {
    if(a[i]==0)
    {
    continue;
    }
    else
    {
    if(a[i]>0)
    {
    cout<<"+"<<a[i];
    }
    if(a[i]<0)
    {
    cout<<"-"<<a[i];
    }
    }
    }
    }
    return 0;
    }

  • 0
    @ 2015-10-24 18:49:50

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <cmath>

    using namespace std;

    int i,j,k,l,n,m;

    int main()
    {
    freopen("poly.in","r",stdin);
    freopen("poly.out","w",stdout);
    cin >>n;
    cin >>m;j=1;
    if (m==0)
    {
    while (m==0 && j<=n)
    {
    j++;
    cin >>m;
    }
    if (m==-1) cout <<"-x^"<<n-j+1;
    else
    if (m==1) cout <<"+x^"<<n-j+1;
    else
    {
    if (m<0) cout <<"-"<<abs(m)<<"x^"<<n-j+1;
    else
    cout <<m<<"x^"<<n-j+1;
    }
    }
    else
    {
    if (m==-1) cout <<"-x^"<<n-j+1;
    else
    if (m==1) cout <<"x^"<<n;
    else
    {
    if (m<0) cout <<"-"<<abs(m)<<"x^"<<n;
    else
    cout <<m<<"x^"<<n;
    }
    }
    for (i=j+1;i<=n-1;i++)
    {
    cin >>m;
    if (m!=0)
    {
    if (m==-1) cout <<"-x^"<<n-i+1;
    else
    if (m==1) cout <<"+x^"<<n-i+1;
    else
    {
    if (m>0) cout <<"+";
    cout <<m<<"x^"<<n-i+1;
    }
    }
    }
    cin >>m;
    if (m!=0)
    {

    if (m==-1) cout <<"-x";
    else
    if (m==1) cout <<"+x";
    else
    {
    if (m>0) cout <<"+";
    cout <<m<<"x";
    }
    }
    cin >>m;
    if (m!=0)
    {
    if (m>0) cout <<"+";
    cout <<m;
    }
    }

  • 0
    @ 2015-02-12 16:12:33

    var a:array[1..1000]of longint;
    n,i,b:longint;
    begin
    readln(n);
    for i:=1 to n+1 do read(a[i]);
    if (a[1]<>0)and(a[1]<>1)and(a[1]<>-1) then write(a[1],'x^',n);
    case a[1] of
    1:write('x^',n);
    -1:write('-x^',n);
    end;
    b:=n-1;
    for i:=2 to n-1 do
    begin
    if a[i]=1 then write('+x^',b)
    else if a[i]=-1 then write('-x^',b)
    else if (a[i]>0) then write('+',a[i],'x^',b)
    else if (a[i]<0) then write('-',-a[i],'x^',b);
    b:=b-1;
    end;
    if a[n]=1 then write('+x') else if a[n]=-1 then write('-x') else if a[n]>1 then write('+',a[n],'x') else if a[n]<-1 then write(a[n],'x');
    if a[n+1]<>0 then if a[n+1]>0 then write('+',a[n+1]) else write(a[n+1]);
    end.

  • 0
    @ 2015-02-11 14:30:16

    var n,f,i:longint;a:array[-1..100000]of longint;

    begin

    readln(n);f:=n;

    for i:=n downto 0 do read(a[i]);

    while(a[f]=0)and(f>=0)do dec(f);

    if f<0 then begin writeln(0);halt;end;

    if f=0 then begin writeln(a[0]);halt;end;

    if a[f]=1 then write('x^',f);

    if a[f]=-1 then write('-x^',f);

    if(a[f]<>1)and(a[f]<>-1)then

    begin

    if f>1 then

    write(a[f],'x^',f)

    else write(a[f],'x');

    end;

    for i:=f-1 downto 2 do

    if a[i]<>0 then

    begin

    if a[i]>0 then write('+');

    if a[i]<>1 then

    begin

    if a[i]<>-1 then write(a[i]);

    if a[i]=-1 then write('-');

    end;

    write('x^',i);

    end;

    if f-1>=1 then

    if a[1]<>0 then

    begin

    if a[1]=1 then write('+x');

    if a[1]=-1 then write('-x');

    if(a[1]<>1)and(a[1]>0)then write('+');

    if(a[1]<>1)and(a[1]<>-1)then write(a[1],'x');

    end;

    if f-1>=0 then

    if a[0]<>0 then

    begin

    if a[0]>0 then write('+');

    writeln(a[0]);

    end;

    end.
    很多没想到,贡献了很多分母啊!正确率掉了2%啊

  • 0
    @ 2014-07-07 19:28:30

    #include <stdio.h>
    #include <math.h>
    int main(){
    int num;
    int i;
    int arr[100];
    scanf("%d",&num);
    for(i=num;i>=0;i--){
    scanf("%d",&arr[i]);
    }
    for(i=num;i>=0;i--){
    if(arr[i]==0) continue;
    if(i!=num){
    if(arr[i]>0) printf("+");
    }
    if(arr[i]<0) printf("-");
    if(abs(arr[i])!=1 || i==0) printf("%d",abs(arr[i]));
    if(i>0){
    printf("x");
    if(i>1) printf("^%d",i);
    }
    }
    printf("\n");
    return 0;
    }

  • 0
    @ 2013-11-04 20:59:50

    program poly;

    var a:array[0..100]of longint;

    n,i:longint;

    ok:boolean;

    begin

    assign(input,'poly.in');

    assign(output,'poly.out');

    reset(input);

    rewrite(output);

    readln(n);

    for i:=n downto 0 do read(a[i]);

    while a[n]=0 do dec(n);

    for i:=n downto 0 do

    if a[i]<>0 then

    begin

    if i=n then

    begin

    if i>1 then

    if abs(a[i])<>1 then if a[i]>0 then write(a[i],'x^',i) else write(a[i],'x^',i)

    else if a[i]=1 then write('x^',i) else write('-x^',i)

    else if i=1 then begin if a[1]>0 then write(a[1],'x') else write(a[1],'x') end

    else if i=0 then write(a[0]);

    end

    else if i=1 then

    begin

    if abs(a[1])<>1 then begin if a[1]>0 then write('+',a[1],'x') else write(a[1],'x'); end

    else if a[1]=1 then write('+x') else write('-x');

    end

    else if i=0 then

    begin

    if a[0]>0 then write('+',a[0]) else write(a[0]);

    end

    else

    if a[i]<>0 then

    begin

    if abs(a[i])<>1 then if a[i]>0 then write('+',a[i],'x^',i) else write(a[i],'x^',i)

    else if a[i]=1 then write('+x^',i) else write('-x^',i);

    end;

    end;

    close(input);

    close(output);

    end.

信息

ID
1812
难度
5
分类
(无)
标签
递交数
2026
已通过
649
通过率
32%
被复制
11
上传者