[ create a new paste ] login | about

Link: http://codepad.org/cKo6ldBa    [ raw code | output | fork ]

C++, pasted on Dec 13:
#include<iostream>
using namespace std;
int main()
{
    long n;
    long q;
    int i,a,b,sum_temp=0,flag=0;
    char act[10];

    cin>>n;
    cin>>q;

    int array[n],temp[n],temp2[n];
    long int sum;
    for(i=0;i<n;i++){
        cin>>temp[i];
        temp2[i]=0;
        array[i]=0;
    }
    while(q>0){
        for(i=0;i<3;i++){
            cin>>act[i];
        }
        act[3]='\0';
        a=act[1]-'0';
        b=act[2]-'0';
        if(act[0]=='S'){
            if(array[b]==0){
                for(i=0;i<=b;i++){
                    if(i>0){
                        array[i]=array[i-1]+temp[i];
                    }else{
                        array[i]=temp[i];
                    }
                }
            }
            sum_temp=0;
            for(i=a;i<=b && flag==1;i++){
                sum_temp=sum_temp+temp2[i];         
            }
            if(a>0){
                sum=(array[b]-array[a-1])+sum_temp;

            }
            else{
                sum=array[b]+sum_temp;
            }

            cout<<sum<<endl;

        }
        else if(act[0]=='G'){
            temp2[a]=b;
            flag=1;
        }
        else if(act[0]=='T'){
            temp2[a]=-b;
            flag=1;
        }
        q--;
    }



    return 0;

}


Output:
1
2
3
In function 'int main()':
Line 13: error: ISO C++ forbids variable-size array 'array'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: