看起来像一个前缀和问题,时间紧急,希望各路大奆能帮助!!个人希望快一点!谢
#include<bits/stdc++.h>
using namespace std;
void shuru(int ,int *);
void shuchu(int ,int *,int );
int q_he(int ,int ,int ,int *);
int main(void)
{
int n;
scanf("%d",&n);
int sz[n];
shuru(n,sz);
int m;
scanf("%d",&m);
shuchu(n,sz,m);
return 0;
}
int q_he(int t,int w,int n,int sz[])//1 3
{
int he = 0;
int i ;
for(i = t - 1;i < w; i++)
{
he += sz[i];
}
return he;
}
void shuchu(int n,int sz[],int m)
{
int t , w;
while( m -- > 0)
{
scanf("%d",&t);
scanf("%d",&w);
printf("%d\n",q_he(t,w,n,sz));
}
}
void shuru(int n,int *sz)
{
while(n -- > 0)
{
scanf("%d",sz++);
}
}