zoukankan      html  css  js  c++  java
  • P1067 多项式输出

    P1067 多项式输出

    我恨模拟题(海星海星)真香again

    题解

    模拟题要注意很多细节

    几组数据了解一下

    代码

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    
    using namespace std;
    
    int n;
    struct node
    {
        int xi;
        char hao;
        int zhi;
        
    }a[105];
    
    int main()
    {
    //    freopen("poly.in","r",stdin);
    //    freopen("poly.out","w",stdout);
        scanf("%d",&n);
        int cnt=0;
        for(int i=n;i>=0;i--)
        {
            int k;
            scanf("%d",&k);
            if(k==0&&n!=0) continue;
            if(cnt==0)
            {
                cnt++;
                a[cnt].xi =k;
                a[cnt].hao ='no';
                a[cnt].zhi =i;
            }
            else
            {
                cnt++;
                if(k>0)
                {
                    a[cnt].xi =k;
                    a[cnt].hao ='+';
                    a[cnt].zhi =i;
                    
                }
                else
                {
                    a[cnt].xi =k;
                    a[cnt].hao ='ye';
                    a[cnt].zhi =i;
                }
            } 
        }
        
        for(int i=1;i<=cnt;i++)
        {
            if(a[i].hao =='no')
            {
                printf("%dx^%d",a[i].xi ,a[i].zhi );
                
            } 
            else
            {
                if(a[i].hao =='+') printf("+"); 
                if(a[i].zhi ==1)
                {
                    if(a[i].xi ==1) printf("x" );
                    else if (a[i].xi ==-1) printf("-x" );
                    else printf("%dx",a[i].xi );
                 } 
                
                else if(a[i].zhi ==0)
                {
                    printf("%d",a[i].xi );
                }
                
                else
                {
                    if(a[i].xi ==1) printf("x^%d",a[i].zhi );
                    else if (a[i].xi ==-1) printf("-x^%d" ,a[i].zhi);
                    else
                    printf("%dx^%d",a[i].xi ,a[i].zhi );
                
                }
                
            } 
        }
        
        return 0;
    }
    
     
  • 相关阅读:
    CSS
    html5
    XHTML
    HTML
    git 教程 --git revert 命令
    Git 教程 --git merge 命令
    git 教程 --git reset 命令
    git 教程 --git cherry-pick 命令
    git 教程 --git stash命令
    git 教程 --git diff功能
  • 原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/11022545.html
Copyright © 2011-2022 走看看