• 入门模拟 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;
    } 

  • 相关阅读:
    ZJOI2019爆蛋记
    NOIp2018退役记
    拓展中国剩余定理(exCRT)摘要
    FFT(快速傅里叶变换)摘要
    主席树摘要
    LCT摘要
    替罪羊树摘要
    FHQ Treap摘要
    逻辑回归1-逻辑回归原理详解
    NLP自然语言处理原理及名词介绍
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12071549.html
Copyright © 2020-2023  润新知