zoukankan      html  css  js  c++  java
  • 洛谷 1067 NOIP2009 普及组 多项式输出

    【题解】

      一道简单的模拟题。需要判一些特殊情况:第一项的正号不用输出,x的一次项不用输出指数,系数为0的项不用输出等等,稍微细心一下就好。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define LL long long
     5 #define rg register
     6 #define N 200010
     7 using namespace std;
     8 int n,m,a[N];
     9 bool last;
    10 inline int read(){
    11     int k=0,f=1; char c=getchar();
    12     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    13     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    14     return k*f;
    15 }
    16 int main(){
    17     n=read();
    18     for(rg int i=n;i;i--){
    19         int x=read();
    20         if(!x) continue;
    21         if(last) putchar(x>0?'+':'-');
    22         else if(x<0) putchar('-');
    23         if(abs(x)!=1) 
    24             if(i!=1) printf("%dx^%d",abs(x),i);
    25             else printf("%dx",abs(x));
    26         else 
    27             if(i!=1) printf("x^%d",i);
    28             else putchar('x');
    29         last=1;
    30     }
    31     int x=read();
    32     if(x!=0){
    33         if(x>0) putchar('+');
    34         printf("%d",x);
    35     }
    36     return 0;
    37 } 
  • 相关阅读:
    ibatis学习笔记
    记ibatis使用动态列查询问题(remapresults)
    jQuery(九)、ajax对象操作
    jQuery(八)、ajax
    jQuery(七)、效果和动画
    jQuery(六)、事件
    jQuery(五)、筛选
    jQuery(四)、文档处理
    jQuery(三)、属性、CSS
    jQuery(二)、选择器
  • 原文地址:https://www.cnblogs.com/DriverLao/p/9891104.html
Copyright © 2011-2022 走看看