zoukankan      html  css  js  c++  java
  • 入门模拟 B1010——一元多项式求导

    2019-12-20

    09:38:48

    What The Fuck? 只通过一个样例?

    scanf("%d",&t)!=EOF这句很重要!
    #include <bits/stdc++.h>
    #include<math.h>
    using namespace std;
    const int MAX_LEN = 10005;
    int main(){
        int temp[MAX_LEN];
        for(int i=0;i<MAX_LEN;++i){
            temp[i] = 0;
        } 
        int t;
        int count = 0;//计数器 
        while(scanf("%d",&t)!=EOF){
            temp[count] = t;
            count++;
        }
        int result[count];
        for(int i =0;i<count;++i){
            result[i] = 0;
        }
        for(int i=0;i<count-1;){
            int temp1 = i;
            int temp2 = i+1;
            result[i]  = temp[temp1] * temp[temp2];
            result[i+1] = temp[temp2]-1;
            i += 2;
        }
        for(int i = 0;i<count-1;++i){
            if(result[i]!=0){
                cout<<result[i]<<" "; 
            }else{
                cout<<result[i];
            }
        }
        system("pause");
        return 0;
    } 

    修复了一个BUG后: 如果求导之后没有任何非零项,需要输出0 0,这是本题的一个陷阱

    #include <bits/stdc++.h>
    #include<math.h>
    using namespace std;
    const int MAX_LEN = 10005;
    int main(){
        int temp[MAX_LEN];
        for(int i=0;i<MAX_LEN;++i){
            temp[i] = 0;
        } 
        int t;
        int count = 0;//计数器 
        while(scanf("%d",&t)!=EOF){
            temp[count] = t;
            count++;
        }
        int result[count];
        for(int i =0;i<count;++i){
            result[i] = 0;
        }
        for(int i=0;i<count-1;){
            int temp1 = i;
            int temp2 = i+1;
            result[i]  = temp[temp1] * temp[temp2];
            result[i+1] = temp[temp2]-1;
            i += 2;
        }
        for(int i = 0;i<count-1;++i){
            if(result[0] == 0){
                printf("0 0");
                break;
            }
            if(result[i]!=0){
                cout<<result[i]<<" "; 
            }else{
                cout<<result[i];
                break;
            }
        }
        system("pause");
        return 0;
    } 

  • 相关阅读:
    Tomcat服务器原理详解
    junit入门
    lombok
    java 运行指定类的main函数
    席位分配问题——惯例Q值法和d&#39;hondt法的MATLAB程序
    5.2 calendar--通用日期的相关函数(3)
    [笔记]软件体系结构(1)--模式初印象
    hdu 1003
    linux虚拟机上挂载U盘
    Android中Java与web通信
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12071549.html
Copyright © 2011-2022 走看看