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;
    } 

  • 相关阅读:
    信息安全基本概念
    GmSSL开发环境搭建及双证书生成
    Git使用教程
    linux软件管理
    在Windows中查看文件的MD5值
    odoo显示页面格式化日期的一个方法
    Ubuntu 查看文件夹大小
    docker容器中启动postgresql 9.5失败:could not locate a valid checkpoint record
    如何让postgresql日志记录所有的执行语句
    vim快捷键
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12071549.html
Copyright © 2011-2022 走看看