我已经制作了一个我必须输入的代码
1 . no of questions
2. difficulty for every question
3 . no. of queries( query is to find median of difficulty questions between questions no. given in next line)
4 . question no.s to find median
循环继续,直到没有输入。
#include<stdio.h>
int main()
{
int ques,count=0;
while(scanf("%d",&ques))
{
int i,diff,se,fi,j,query,arr[100];
for(i=0;i<ques;i++)
{
scanf("%d",&diff);
arr[i] = diff;
}
count++;
printf("Case %d:\n",count);
scanf("%d",&query);
for(i=0;i<query;i++)
{
int sum = 0;
scanf("%d %d",&fi,&se);
for(j=fi-1;j<se;j++)
{
sum = sum+ arr[j];
}
sum = sum/((se-fi)+1);
printf("%d\n",sum);
}
}
return 0;
}
在这里我给出两个输入
5
5 3 2 4 1
3
1 3
2 4
3 5
5
10 6 4 8 2
4
1 3
2 4
3 5
2 3
6
2 56 2 3 5 4
1
2 5
但我的输出应该只达到案例 3:
Case 1:
3
3
2
Case 2:
6
6
4
5
Case 3:
16
Case 4:
4
Case 5:
4
Case 6:
4
Case 7:
4
Case 8:
4
Case 9:
4
Case 10:
4
Case 11:
4
Case 12:
4
Case 13:
4
Case 14:
4
Case 15:
4
它继续下去:告诉我为什么会这样: